python-itertools

itertools.accumulate(iterable[, func])

  1. make an iterator via some kind of function,for example an iterator that returns accumulated sums, or accumulated results of other binary functions
  2. it is a function with two arguments,func is optional,argument iterable can be any type that be accepted to the func.
  3. Example

from itertools import *
import operator

data = [3, 4, 6, 2, 1, 9, 0, 7, 5, 8]
print(list(accumulate(data, operator.mul)))

print(list(accumulate(data,operator.add)))

[3, 12, 72, 144, 144, 1296, 0, 0, 0, 0]
[3, 7, 13, 15, 16, 25, 25, 32, 37, 45]