Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 95)
95.
What is the purpose of the
itertools.chain()
function when used with generators?
Answer: Option
Explanation:
itertools.chain()
is used to chain multiple iterables (including generators) together, producing a single iterable that yields elements from each iterable in sequence.
import itertools
gen1 = (1, 2, 3)
gen2 = ('a', 'b')
chained_iterable = itertools.chain(gen1, gen2)
print(list(chained_iterable)) # Output: [1, 2, 3, 'a', 'b']
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