Return an iterator that applies functionto every item of iterable, yielding the results. If additional iterable arguments are passed, function must take that many arguments andis applied to the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is exhausted. For cases where the function inputs are already arranged into argument tuples, see itertools.starmap().
filter
1 2 3 4 5 6 7 8
filter(function, iterable)
Construct an iterator from those elements of iterable for which functionreturnstrue. iterable may be either a sequence, a container which supports iteration, or an iterator. IffunctionisNone, the identityfunctionis assumed, that is, all elements of iterable that are false are removed.
Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable iffunction(item)) iffunctionisnotNoneand (item for item in iterable if item) iffunctionisNone.
See itertools.filterfalse() for the complementary function that returns elements of iterable for which functionreturnsfalse.