Python filter() Syntax
The filter() method in Python has the following syntax:
Syntax: filter(function, sequence)
Parameters:
- function: function that tests if each element of a sequence is true or not.
- sequence: sequence which needs to be filtered, it can be sets, lists, tuples, or containers of any iterators.
Returns: an iterator that is already filtered.
filter() in python
The filter() method filters the given sequence with the help of a function that tests each element in the sequence to be true or not.