Sometimes, while working with Python list, we can have a problem in which we have to filter a list. This can sometimes, come with variations. One such variation can be filtering by the use of Boolean list. Let’s discuss a way in which this task can be done.
Method : Using
The most elegant and straightforward method to perform this particular task is to use inbuilt functionality of compress() to filter out all the elements from list which exists at Truth positions with respect to index of other list.
The original list : [6, 4, 8, 9, 10] The bool list is : [True, False, False, True, True] List after filtering is : [6, 9, 10]
- Python | Filter list of strings based on the substring list
- Python | Filter a list based on the given list of strings
- Python | Filter even values from a list
- Python | Unique dictionary filter in list
- Python - Filter float strings from String list
- Python | Filter tuples according to list element presence
- Python - Filter list elements starting with given Prefix
- Python | Filter dictionary key based on the values in selective list
- Python | Boolean list initialization
- Python | Boolean List AND and OR operations
- Python - False indices in a boolean list
- Python program to fetch the indices of true values in a Boolean list
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python | Convert mixed data types tuple list to string list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.