Skip to content

Instantly share code, notes, and snippets.

@LeoHuckvale
Last active August 29, 2015 14:05
Show Gist options
  • Save LeoHuckvale/0de6f55eceb8c3b4c8b5 to your computer and use it in GitHub Desktop.
Save LeoHuckvale/0de6f55eceb8c3b4c8b5 to your computer and use it in GitHub Desktop.
"un"-zipping in Python
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