Last active
August 29, 2015 14:05
-
-
Save LeoHuckvale/0de6f55eceb8c3b4c8b5 to your computer and use it in GitHub Desktop.
"un"-zipping in Python
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
def breakfast(i): | |
"""Some function that returns a tuple""" | |
spam = i | |
eggs = i | |
return spam, eggs | |
# A list comprehension that generates results | |
results = [breakfast(i) for i in range(1, 4)] | |
## or, if you like that sort of thing: | |
# results = map(breakfast, range(1, 4)) | |
# "un-zip" to split the results | |
spamses, eggses = zip(*results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment