In this lesson, you’ll learn how to use the reduce()
function (or functools.reduce()
in Python 3), which is one of the functional programming primitives (or building blocks) available in Python. It takes a function, a sequence (or iterable), and an optional initial value.
You’ll walk through how you can use the reduce()
function with the data set that you’ve been using in this course to reduce a sequence to a sinlge output value by applying a function repeatedly in order to output a single value.
breaves on March 29, 2020
So you’ve basically defined the function def f(acc,val): return acc+val[‘age’]
So each item of the sequence is always applied to the SECOND argument of the function, right? Could as well be def f(x,y): return x+y[‘age’] and it’s basically calling for s in sequence: x=f(x,s) return x
right?