Terminating iterators

Terminating iterators return values until the shortest input sequence has been iterated through, then it terminates:

  1. The accumulate(iterable[, func]) function returns an iterator of accumulated sums, or the results of other binary functions, as determined by the value provided to the func argument. If func is provided, it should be a function of two arguments. The iterable elements can be any type that can be used by func as arguments. The default function is addition. The following example shows this default functionality:

As the default function is addition, using accumulate to add a range of five numbers returns ...

Get Secret Recipes of the Python Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.