In this section, you’ll discover another basic of functional programming: how to use the reduce()
function to transform data structures.
We’ll take an example data set represented using an immutable data structure from the previous lessons in this course, and then we’ll create a reduced or derived output from that data using Python’s built-in reduce()
function.
reduce()
(or functools.reduce()
in Python 3) is one of the functional programming primitives (or building blocks) available in Python. It’s useful in a number of contexts.
Later in this section, you’ll see how the reduce()
function lets you group your data set into arbitrary categories. You’ll also learn about Python’s defaultdict
class defined in the collections
module, as well as some useful helpers in the itertools
module, like itertools.groupby
.
David McConnell on March 26, 2020
What are you using here as your IDE? I like the descriptive docstrings, but don’t see them with IDLE, PyCharm, or Spyder.