Functional Python Programming

(Wang) #1

The Itertools Module


We've also looked at a number of finite iterators. Some of these are built-in and some
of these are part of the itertools module. These work with a source iterable, so they
terminate when that iterable is exhausted. These functions include enumerate(),
accumulate() , chain() , groupby() , zip_longest(), zip(), compress(),
islice(), dropwhile(), takewhile(), filterfalse(), filter(), starmap(), and
map(). These functions allow us to replace possibly complex generator expressions
with simpler-looking functions.


Additionally, we looked at the recipes from the documentation, which provide yet
more functions we can study and copy for our own applications. The recipes list
shows a wealth of common design patterns.


In Chapter 9, More Itertools Techniques, we'll continue our study of the itertools
module. We'll look at the iterators focused on permutations and combinations.
These don't apply to processing large sets of data. They're a different kind of
iterator-based tool.

Free download pdf