From the course: Functional Programming with Python
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reducing - Python Tutorial
From the course: Functional Programming with Python
Reducing
- [Instructor] The final function that we're going to discuss in this course is called reduce. The purpose of this function might not be quite as apparent as say map or filter, but reduce is definitely just as useful as, if not more useful, than the other array functions. So what reduce allows us to do is take a list or any other iterable and reduce it down to a single value. So for example we could take a list of numbers and reduce it down to a sum or an average. Essentially what a reduce does is it starts with first element in the list and builds on this initial value in some way until after we've processed all of our elements we end up with the result. In the case of finding the sum of a list of numbers for example, we'd add each element to the initial value. Or if we were trying to find the product of a list of numbers, we'd multiply each element by the initial value and so on. So what's the syntax of reduce? Well…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Python: The functional parts1m 5s
-
(Locked)
Mapping4m 46s
-
(Locked)
Filtering3m 20s
-
(Locked)
Lambdas in Python4m 25s
-
(Locked)
List comprehensions in Python3m 35s
-
(Locked)
Reducing4m 53s
-
(Locked)
Combining list functions7m 15s
-
(Locked)
Challenge: Converting to list comprehensions52s
-
(Locked)
Solution: Converting to list comprehensions3m 30s
-
(Locked)
-
-