Python filter() function
The filter() method facilitates a functional approach to Python programming . It allows the developer to write simpler, shorter code , without necessarily needing to bother about intricacies like loops and branching.
The filter() method returns an iterator were the items are filtered through a function to test if the item is accepted or not. The returned iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None , the identity function is assumed, that is, all elements of iterable that are false are removed.
- function : The function that tests if elements of an iterable returns true or false.
- iterable : The iterable to be filtered.