Chapter 4. Working with Collections
Python offers a number of functions that process whole collections. They can be applied to sequences (lists or tuples), sets, mappings, and iterable results of generator expressions. We'll look at some of Python's collection-processing functions from a functional programming viewpoint.
We'll start out by looking at iterables and some simple functions that work with iterables. We'll look at some additional design patterns to handle iterables and sequences with recursion as well as explicit for
loops. We'll look at how we can apply a scalar()
function to a collection of data with a generator expression.
In this chapter, we'll show examples of how to use the following functions to work with collections:
any()
andall()
len()
andsum()
and some higher-order statistical processing related to these functionszip()
and some related techniques to structure and flatten lists of datareversed()
enumerate()
The first four functions...