Created
July 9, 2019 04:14
-
-
Save eyaltrabelsi/d039740e4653b6e26bbb6858f3ae8285 to your computer and use it in GitHub Desktop.
Python trick Combining two iterables of tuples with padding or pivot nested iterable with padding.
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
>>> import itertools as it | |
>>> x = [1, 2, 3, 4, 5] | |
>>> y = ['a', 'b', 'c'] | |
>>> list(zip(x, y)) | |
[(1, 'a'), (2, 'b'), (3, 'c')] | |
>>> list(it.zip_longest(x, y)) | |
[(1, 'a'), (2, 'b'), (3, 'c'), (4, None), (5, None)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment