Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 98)
98.
How does the
itertools.zip_longest()
function behave when used with generators of unequal lengths?
Answer: Option
Explanation:
itertools.zip_longest()
continues until the longest iterable is exhausted, filling in missing values with a specified fillvalue.
import itertools
gen1 = (1, 2, 3)
gen2 = ('a', 'b')
zipped_iterable = itertools.zip_longest(gen1, gen2, fillvalue=None)
print(list(zipped_iterable)) # Output: [(1, 'a'), (2, 'b'), (3, None)]
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers