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.
filter(function, sequence) Parameters: function: function that tests if each element of a sequence true or not. sequence: sequence which needs to be filtered, it can be sets, lists, tuples, or containers of any iterators. Returns: returns an iterator that is already filtered.
The filtered letters are: e e
It is normally used with Lambda functions to separate list, tuple, or sets.
[1, 3, 5, 13] [0, 2, 8]
Please refer Python Lambda functions for more details.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course