3.7 Applying generators to built-in collections
We’ll now look at ways to apply generator expressions to a number of Python’s built-in collections. This section will cover the following topics:
Generators for lists, dicts, and sets
Working with stateful collections
Using the
bisect
module to create a mappingUsing stateful sets
Each of these looks at some specialized cases of Python collections and generator functions. In particular, we’ll look at ways to produce a collection, and consume the collection in later processing.
This is a lead-in to the next chapter, Chapter 4, Working with Collections, which covers the Python collections in considerably more detail.
3.7.1 Generators for lists, dicts, and sets
A Python sequence object, such as a list, is iterable. However, it has some additional features. We can think of a list as a materialized iterable. We’ve used the tuple()
function in several examples to collect the output of a generator expression...