Fix the Broken Pipeline
Intermediate · Fix the bug · from Python map(), filter(), reduce(), and Higher-Order Functions
From the lesson: Python map(), filter(), reduce(), and Higher-Order Functions
Picture an assembly line in a factory. Raw materials enter at one end. At the first station, each piece is shaped. At the next station, defective pieces are removed. At the final station, all the good pieces are combined into one finished product.
Read the lessonThis code should convert a list of temperature strings like ["32F", "100F", "212F"] into Celsius integers. But it has two bugs.
Expected output:
[0, 38, 100]Formula: Celsius = (Fahrenheit - 32) * 5 / 9, then round to the nearest integer.
temps = ["32F", "100F", "212F"]
# Bug 1: Need to extract the number from the string
# Bug 2: Formula or conversion issue
result = list(map(lambda t: int((t - 32) * 5 / 9), temps))
print(result)
More Map, Filter and Reduce exercises
- Square Every NumberBeginner
- Filter Out Short WordsBeginner
- Predict the Pipeline OutputBeginner
- Find the Product with reduce()Intermediate
- Build a Data PipelineAdvanced
- Refactor to a List ComprehensionAdvanced
All Python exercises · 50 practice problems · Functions quiz