Skip to content

Instantly share code, notes, and snippets.

@Avery2
Created March 25, 2022 22:25
Show Gist options
  • Save Avery2/6973896adf1487f55544a21357e83365 to your computer and use it in GitHub Desktop.
Save Avery2/6973896adf1487f55544a21357e83365 to your computer and use it in GitHub Desktop.
How to use zip_longer to create a zip that uses the length of the longer of the two iterables
import itertools
a = [i for i in range(10)]
b = [chr(ord('a') + i) for i in range(5)]
print(f"{len(list(itertools.zip_longest(a, b)))=}")
for x, y in itertools.zip_longest(a, b):
print(f"{x=} {y=}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment