Skip to content

Instantly share code, notes, and snippets.

Created Jul 6, 2020
What would you like to do?
import itertools
#fillvalue is not given,by default it will be None.
#iteration continues until longest iterable is exhausted.
print (z1)#Output:<itertools.zip_longest object at 0x00AA3BE0>
#we can iterate through zip object using for loop or we can convert to list object.
print (list(z1))#Output:[(1, 'a'), (2, 'b'), (3, 'c'), (4, None), (5, None)]
#fillvalue is mentioned
print (list(z2))#Output:[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'z'), (5, 'z')]
#using zip(),iteration continues until shorest iterable is exhausted.
print (list(z3))#Output:[(1, 'a'), (2, 'b'), (3, 'c')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment