Python filter function exercises
Python Filter Function [11 exercises]:
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
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.
1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/filter/index.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics