Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Functional programming design patterns


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:

  • We can process items in large collections of data, creating additional collections that are copies, subsets, or transformations.

  • We can process items...