Get an accumulated sum of numbers in an iterable
suggest changeaccumulate
yields a cumulative sum (or product) of numbers.
>>> import itertools as it
>>> import operator
>>> list(it.accumulate([1,2,3,4,5]))
[1, 3, 6, 10, 15]
>>> list(it.accumulate([1,2,3,4,5], func=operator.mul))
[1, 2, 6, 24, 120]
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents