Congratulations, you made it to the end of the course! itertools is a powerful module in the Python standard library, and an essential tool to have in your toolkit. With it, you can write memory-efficient code that’s often shorter and easier to read, although that isn’t always the case.
In this video course, you learned how to:
- Compose iterators into lazy pipelines that use a fraction of the memory of list-based code
- Split data into chunks with
batched(), and flatten it again withchain.from_iterable() - Brute-force problems with
combinations(),permutations(), andproduct() - Generate infinite sequences with
count(),repeat(), andcycle(), and running totals withaccumulate() - Analyze real data with
pairwise(),filterfalse(),takewhile(),dropwhile(), andgroupby()
This course skipped two itertools functions: starmap() and compress(). Read their docs and experiment with your own use cases! The module also keeps growing: pairwise() and batched() arrived years after the rest, so keep an eye on the What’s New pages for each Python release. For even more tools for constructing iterators, take a look at more-itertools.
Resources mentioned in this lesson: