Functional Functions
functools.reduce()
Fold an iterable from left to right using a two-argument function. Without an initial value, the first item starts the fold; empty input then raises TypeError.
Formal Syntax & Structure
python syntaxpython
functools.reduce(function, iterable[, initial])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| function | callable | Callable applied by the operation. |
| iterable | iterable | Input values, consumed as needed. |
| initial | object | Optional initial accumulator; explicitly passing None uses None as that value. |
Return Value
object
The object result described above.
Working Example
Example Snippetpython
import functoolsprint(functools.reduce(lambda a,b:a*b,[2,3,4]))