w3resource

Python filter function exercises


This resource offers a total of 55 Python Filter Function problems for practice. It includes 11 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

The following exercises are related to the filter function in Python. This is used for functional programming to filter elements from a sequence based on a given condition.

[An Editor is available at the bottom of the page to write and execute the scripts.]


1. Even Number Filter

Write a Python function that filters out even numbers from a list of integers using the filter function.

Click me to see the sample solution


2. Uppercase Extractor

Write a Python program that uses the filter function to extract all uppercase letters from a list of mixed-case strings.

Click me to see the sample solution


3. Threshold Filter

Write a Python function that filters out all elements less than or equal than a specified value from a list of numbers using the filter function.

Click me to see the sample solution


4. Vowel Name Filter

Write a Python program that creates a list of names and uses the filter function to extract names that start with a vowel (A, E, I, O, U).

Click me to see the sample solution


5. Empty String Remover

Write a Python function that filters out all empty strings from a list of strings using the filter function.

Click me to see the sample solution


6. Student Grade Filter

Write a Python program that creates a list of dictionaries containing student information (name, age, grade) and uses the filter function to extract students with a grade greater than or equal to 95.

Click me to see the sample solution


7. Prime Number Excluder

Write a Python program that filters out prime numbers from a list of integers using the filter function.

Click me to see the sample solution


8. Word Length Filter

Write a Python program that creates a list of words and use the filter function to extract words that contain more than five letters.

Click me to see the sample solution


9. Substring Excluder

Write a Python function that filters out elements from a list of strings containing a specific substring using the filter function.

Click me to see the sample solution


10. Future Date Filter

Write a Python program that implements a Python program that filters out dates (in the format "YYYY-MM-DD") that are in the future using the filter function.

Click me to see the sample solution


11. City Population Filter

Write a Python program that creates a list of tuples, each containing a city name and its population. Use the filter function to extract cities with a population greater than 2 million.

Click me to see the sample solution


Python Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.