Accumulation

Contents

The accumulate functionitertools.accumulate gives a running total.

Addition

For example, let’s try accumulating the numbers (1, 2, 3, 4, …):

>>> it = accumulate(count(1))

>>> list(islice(it, 8))
[1, 3, 6, 10, 15, 21, 28, 36]

Sign up for access to the full page, plus the complete archive and all the latest content.