Created
March 25, 2022 22:25
-
-
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
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 | |
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