itertools

The itertools library contains iterable functions inspired by those available in functional languages. All of these are iterable and have been constructed in such a way that only a minimal amount of memory is required to process even the largest of datasets. While you can easily write most of these functions yourself using a simple function, I would still recommend using the ones available in the itertools library. These are all fast, memory efficient, and—perhaps more importantly—tested.

Note

Even though the titles of the paragraphs are capitalized, the functions themselves are not. Be careful not to accidently type Accumulate instead of accumulate.

accumulate – reduce with intermediate results

The accumulate function is very similar to ...

Get Mastering Python 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.