Practice Using Filter Function - 25.1.2 | 25. List Comprehension | Data Structures and Algorithms in Python
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Academics
Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Professional Courses
Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skillsβ€”perfect for learners of all ages.

games

Practice Questions

Test your understanding with targeted questions related to the topic.

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.

Practice 4 more questions and get performance evaluation

Interactive Quizzes

Engage in quick quizzes to reinforce what you've learned and check your comprehension.

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.

Solve 1 more question and get performance evaluation

Challenge Problems

Push your limits with challenges.

Question 1

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.

Question 2

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.

Challenge and get performance evaluation