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 a list based on the given list of strings
- Python | Filter list of strings based on the substring list
- Python - Filter the List of String whose index in second List contaons the given Substring
- Python | Filter even values from a list
- Python | Filter dictionary key based on the values in selective list
- Python | Unique dictionary filter in list
- Python | Filter tuples according to list element presence
- Python - Filter float strings from String list
- Python - Filter list elements starting with given Prefix
- Python - Filter all uppercase characters Tuples from given list of tuples
- Python - Filter Tuples by Kth element from List
- Python | Boolean list initialization
- Python program to fetch the indices of true values in a Boolean list
- Python | Boolean List AND and OR operations
- Python - False indices in a boolean list
- Python | Filter the negative values from given dictionary
- Python - Filter unequal elements of two lists corresponding same index
- Python - Filter above Threshold size Strings
- Python - Filter Range Length Tuples
- Python | Filter Tuple Dictionary Keys
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.