Reduce a List to Find the Maximum
Intermediate · Write the code · from Python functools: lru_cache, partial, reduce, singledispatch
From the lesson: Python functools: lru_cache, partial, reduce, singledispatch
Imagine your functions could remember past answers, come pre-loaded with some arguments, or automatically handle different data types. That's what the functools module gives you: power-ups for your functions.
Read the lessonUse reduce with a lambda to find the maximum value in [34, 12, 89, 45, 23, 67]. Print the result. Your lambda should compare two values and return the larger one.
from functools import reduce
numbers = [34, 12, 89, 45, 23, 67]
# Use reduce to find the maximum
More functools exercises
- Cache a Factorial FunctionIntermediate
- Create a Percentage Calculator with partialIntermediate
- Predict the partial OutputBeginner
- Build a String with reduceAdvanced
- Create a singledispatch FormatterAdvanced
- Fix the Caching BugAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz