Get an accumulated sum of numbers in an iterable

suggest change

accumulate 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]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents