Overview:
- The built-in function filter() returns an instance of class filter, which is an iterator that returns the next item in the iterable(while calling __next()__ on it) for which the predicate function returns True.
- If no predicate is passed to the filter() constructor, the __next__() method returns the next element in the iterable that evaluates as True.
Example:
# Example Python program that uses the built-in function # A list of colors as RGB tuples # A predicate function returning False for all Gray variants # Call to built-in function filter to exclude Gray colors # Print the colors after filtering |
Output:
<class 'filter'> |