Skip to content

Instantly share code, notes, and snippets.

@williamn
Created February 1, 2013 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamn/4694916 to your computer and use it in GitHub Desktop.
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.
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