Iteration Classes
itertools.accumulate()
Emit running totals or successive results of a binary function. A non-None initial value is emitted first. Without it, the first input is the initial result.
Formal Syntax & Structure
python syntaxpython
itertools.accumulate(iterable, func=None, *, initial=None)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable | Input values, consumed as needed. |
| func | callable or None | Binary accumulation function; None selects addition. |
| initial | object | Optional initial accumulator. |
Return Value
iterator
The iterator result described above.
Working Example
Example Snippetpython
import itertoolsprint(list(itertools.accumulate([2,3,4])))