[itertools] accumulate()
itertools Functions creating iterators for efficient looping itertools.accumulate() Make an iterator that returns accumulated sums, or accumulated results of other binary functions (specified via the optional func argument) def accumulate(iterable, func=operator.add, *, initial=None): 'Return running totals' # accumulate([1,2,3,4,5]) --> 1 3 6 10 15 # accumulate([1,2,3,4,5], initial=100) --> 100..