Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 90)
90.
What is the purpose of the
itertools.accumulate()
function when used with generators?
Answer: Option
Explanation:
itertools.accumulate()
applies a specified function cumulatively to the elements of a generator, yielding the intermediate results.
import itertools
gen = (1, 2, 3, 4)
accumulated_iterable = itertools.accumulate(gen, lambda x, y: x + y)
print(list(accumulated_iterable)) # Output: [1, 3, 6, 10]
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