EDIT: My question is not a duplicate as someone has marked. The other question is incorrect and does not even work.
I have tried a few ways to group the results of itertools.combinations and been unable to come up with the correct output. It is needed to create matches in a game. Every team needs to play every day, but only once. Teams need to play different teams on the following days until everyone has played everyone.
teams = [team 1, team 2, team 3, team 4]
print list(itertools.combinations(teams, 2))
the result:
[(team 1, team 2), (team 1, team 3), (team 1, team 4), (team 2, team 3), (team 2, team 4), (team 3, team 4)]
But what I need is to group them without any duplicate list items. example:
[
[(team 1,team 2), (team 3,team 4)], #day 1
[(team 1,team 3), (team 2,team 4)], #day 2
[(team 1,team 4), (team 2,team 3)] #day 3
]
Any tips would be appreciated, I feel like there's probably a simple one-liner to get this done.