Created
June 22, 2019 05:02
-
-
Save eyaltrabelsi/818d72d9fed03cc9759354bacc15ca1e to your computer and use it in GitHub Desktop.
Python trick zip function
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
# 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