Skip to content

Instantly share code, notes, and snippets.

@eyaltrabelsi
Created July 9, 2019 04:14
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/d039740e4653b6e26bbb6858f3ae8285 to your computer and use it in GitHub Desktop.
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.
>>> 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