Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

The reduce() Function: Overview

Give Feedback

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.

Comments & Discussion

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.

Ankit Chouhan on March 27, 2020

He is using bpython. sudo apt-get install bpython

Become a Member to join the conversation.