Build a String with reduce
Advanced · 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 to join the list ['Python', 'is', 'awesome'] into a single string with spaces between words. Use a lambda that concatenates two strings with a space. Print the result.
from functools import reduce
words = ['Python', 'is', 'awesome']
# Use reduce to join words with spaces
More functools exercises
- Cache a Factorial FunctionIntermediate
- Create a Percentage Calculator with partialIntermediate
- Reduce a List to Find the MaximumIntermediate
- Predict the partial OutputBeginner
- Create a singledispatch FormatterAdvanced
- Fix the Caching BugAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz