-
-
Save IndhumathyChelliah/bd8d4b11ceb1fb27056eaa268826cb8b to your computer and use it in GitHub Desktop.
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 | |
#fillvalue is not given,by default it will be None. | |
#iteration continues until longest iterable is exhausted. | |
z1=itertools.zip_longest([1,2,3,4,5],['a','b','c']) | |
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 | |
z2=itertools.zip_longest([1,2,3,4,5],['a','b','c'],fillvalue="z") | |
print (list(z2))#Output:[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'z'), (5, 'z')] | |
#using zip(),iteration continues until shorest iterable is exhausted. | |
z3=zip([1,2,3,4,5],['a','b','c']) | |
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