Practice - Using Filter Function
Practice Questions
Test your understanding with targeted questions
Define a function is_positive(n) that returns True if n is positive, and False otherwise. Use filter to get positive numbers from the list [-1, 0, 1, 2, -2].
💡 Hint: Remember to define the function before using filter.
Using filter, extract numbers greater than 10 from the list [5, 10, 15, 20, 25].
💡 Hint: Think about how you would compare each element.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What does the filter function do in Python?
💡 Hint: Think about what filtering means in everyday terms.
True or False: List comprehensions can replace both map and filter functions in Python.
💡 Hint: Consider the structure of a list comprehension.
1 more question available
Challenge Problems
Push your limits with advanced challenges
Create a Python function that takes a list of numbers, applies filter to extract only positive numbers, and then uses map to square these numbers. Return the final result.
💡 Hint: Think about using lambdas for both filtering and mapping.
Refactor your function to use list comprehension instead of filter and map to achieve the same result with a cleaner syntax.
💡 Hint: Remember to incorporate both the condition and the transformation together.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.