Created
May 26, 2012 02:53
-
-
Save TimFletcher/2791847 to your computer and use it in GitHub Desktop.
Lists vs Generators
This file contains 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
# Using lists | |
def allcombinations(starters, endings): | |
result = [] | |
for s in starters: | |
for e in endings: | |
result.append(s+e) | |
return result | |
# Using a generator | |
def allcombinations(starters, endings): | |
for s in starters: | |
for e in endings: | |
yield s+e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment