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

Reducing - Python Tutorial

From the course: Functional Programming with Python

Start my 1-month free trial

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…

Contents