The presence of higher-order functions in Python allows us to leverage a great many functional programming design patterns. To learn more about these design patterns, a good place to start is the itertools
module. The functions in this module provide many examples of how we can write simple functions that do sophisticated processing.
Additionally, we can use some of the features in the functools
module. This contains the general-purpose reduce()
function. It also contains some functions that can help us write decorators. A decorator, as we'll see in Chapter 13, Metaprogramming and Decorators, is another kind of higher-order function: it's a function that modifies the definition of an original function. This is another aspect of functional programming.
Most importantly, we have two ways to approach algorithms: