Skip to content

Instantly share code, notes, and snippets.

@eyaltrabelsi
Created June 22, 2019 05:02
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 eyaltrabelsi/818d72d9fed03cc9759354bacc15ca1e to your computer and use it in GitHub Desktop.
Save eyaltrabelsi/818d72d9fed03cc9759354bacc15ca1e to your computer and use it in GitHub Desktop.
Python trick zip function
# Combining two iterables
>>> a = [1, 2, 3]
>>> b = ['a', 'b', 'c']
>>> z = zip(a, b)
>>> z
[(1, 'a'), (2, 'b'), (3, 'c')]
# Pivoting list of tuples
>>> zip(*z)
[(1, 2, 3), ('a', 'b', 'c')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment