PyDocs

Nav

Functional Programming Modules

reduce

functools

function
  • reduce(function, iterable, /[, initial])
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.

This effectively reduces the iterable to a single value.  If initial is
present, it is placed before the items of the iterable in the
calculation, and serves as a default when the iterable is empty.

For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1 + 2) + 3) + 4) + 5).
Changed in 3.14
  • 3.14: initial is now supported as a keyword argument.
0 Examples
No examples for functools/reduce.
See Also
No see-alsos for functools/reduce
0 Notes
No notes for reduce