9.5 Summarizing a collection – how to reduce
A reduction is the generalized concept behind computing a summmary like the total or the maximum of a collection of numbers. Computing statistical measures like mean or variance are also reductions. In this recipe, we’ll look at several summarization or reduction techniques.
In the introduction to this chapter, we noted that there are three processing patterns that Python supports elegantly: map, filter, and reduce. We saw examples of mapping in the Applying transformations to a collection recipe and examples of filtering in the Picking a subset – three ways to filter recipe.
The third common pattern is reduction. In the Designing classes with lots of processing and the Extending a built-in collection – a list that does statistics recipes, we looked at class definitions that computed a number of statistical values. These definitions relied — almost exclusively — on the built...