Practice Using Filter Function (25.1.2) - List Comprehension - Data Structures and Algorithms in Python
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Using Filter Function

Practice - Using Filter Function

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

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.

Question 2 Easy

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

Question 1

What does the filter function do in Python?

Extracts elements based on a condition
Transforms elements
Both A and B

💡 Hint: Think about what filtering means in everyday terms.

Question 2

True or False: List comprehensions can replace both map and filter functions in Python.

True
False

💡 Hint: Consider the structure of a list comprehension.

1 more question available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

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.

Challenge 2 Hard

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.