Filter Out Short Words
Beginner · Write the code · 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 lessonUse filter() with a lambda to keep only words that have more than 3 characters.
Given: ["hi", "hello", "hey", "world", "ok", "python"]
Print the result as a list.
Expected output:
['hello', 'world', 'python']words = ["hi", "hello", "hey", "world", "ok", "python"]
# Use filter() to keep words longer than 3 characters
More Map, Filter and Reduce exercises
- Square Every NumberBeginner
- Predict the Pipeline OutputBeginner
- 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