Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Python itertools By Example (Summary)

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 with chain.from_iterable()
  • Brute-force problems with combinations(), permutations(), and product()
  • Generate infinite sequences with count(), repeat(), and cycle(), and running totals with accumulate()
  • Analyze real data with pairwise(), filterfalse(), takewhile(), dropwhile(), and groupby()

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:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.