How to use 'functools reduce' in Python

Every line of 'functools reduce' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
19def reduce(
20 self, f: Callable[[B, A], B], initializer: Optional[B] = None
21) -> B:
22 """
23 Aggregate elements by ``f``
24
25 Example:
26 >>> List(range(3)).reduce(lambda a, b: a + b)
27 3
28
29 Args:
30 f: Function to perform aggregation
31 initializer: Starting value for aggregation
32 Return:
33 Aggregated result
34 """
35 return reduce(f, self, initializer) # type: ignore

Related snippets