Created
February 1, 2013 23:32
-
-
Save williamn/4694916 to your computer and use it in GitHub Desktop.
Along with the collections library python also has a library called itertools which has really cool efficient solutions to problems. One is finding all combinations. This will tell us all the different ways the teams can play each other.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
teams = ["Packers", "49ers", "Ravens", "Patriots"] | |
for game in combinations(teams, 2): | |
print game | |
# => ('Packers', '49ers') | |
# => ('Packers', 'Ravens') | |
# => ('Packers', 'Patriots') | |
# => ('49ers', 'Ravens') | |
# => ('49ers', 'Patriots') | |
# => ('Ravens', 'Patriots') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment