The builtin filter()
function filters out and returns the elements of an iterable that evaluates to True
when a particular function is applied on them. The itertools.filterfalse()
function serves the opposite purpose by filtering out and returning only those elements that evaluates to False
.
As you can see in the above example, the two functions returns opposite results given the same function as key.
filterfalse(func, iterable)
func |
Required. The function to be used in filtering. If None is given as the argument, the elements will be filtered by their boolean values. |
iterable |
Required. The iterable object containing the elements to be filtered. |
The function returns an iterator object which returns only those items in the iterable
for which function(item)
evaluates to False
.