@MariaZverina 的代码不起作用,我也使用 Round-robin_tournament 实现了此代码:
teams = ["Team1", "Team2", "Team3", "Team4", "Team5", "Team6"]
if len(teams) % 2:
teams.append('Day off')
n = len(teams)
matchs = []
fixtures = []
return_matchs = []
for fixture in range(1, n):
for i in range(n/2):
matchs.append((teams[i], teams[n - 1 - i]))
return_matchs.append((teams[n - 1 - i], teams[i]))
teams.insert(1, teams.pop())
fixtures.insert(len(fixtures)/2, matchs)
fixtures.append(return_matchs)
matchs = []
return_matchs = []
for fixture in fixtures:
print fixture
输出:
[('Team1', 'Team6'), ('Team2', 'Team5'), ('Team3', 'Team4')]
[('Team1', 'Team5'), ('Team6', 'Team4'), ('Team2', 'Team3')]
[('Team1', 'Team4'), ('Team5', 'Team3'), ('Team6', 'Team2')]
[('Team1', 'Team3'), ('Team4', 'Team2'), ('Team5', 'Team6')]
[('Team1', 'Team2'), ('Team3', 'Team6'), ('Team4', 'Team5')]
[('Team6', 'Team1'), ('Team5', 'Team2'), ('Team4', 'Team3')]
[('Team5', 'Team1'), ('Team4', 'Team6'), ('Team3', 'Team2')]
[('Team4', 'Team1'), ('Team3', 'Team5'), ('Team2', 'Team6')]
[('Team3', 'Team1'), ('Team2', 'Team4'), ('Team6', 'Team5')]
[('Team2', 'Team1'), ('Team6', 'Team3'), ('Team5', 'Team4')]