Predict the Pipeline Output
Beginner · Predict the output · 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 lessonRead this code and predict the output. Then write a print() statement that produces the exact same output.
numbers = [10, 25, 30, 45, 50]
result = list(map(lambda x: x // 10, filter(lambda x: x >= 30, numbers)))
print(result)Think step by step: what does filter keep, then what does map do to each item?
# Print the exact output
More Map, Filter and Reduce exercises
- Square Every NumberBeginner
- Filter Out Short WordsBeginner
- Fix the Broken PipelineIntermediate
- Find the Product with reduce()Intermediate
- Build a Data PipelineAdvanced
- Refactor to a List ComprehensionAdvanced
All Python exercises · 50 practice problems · Functions quiz