This function is used to traverse all elements from an iterative object iterable , and evaluates to True When each element is run as a parameter to a function object. element is preserved, while the element that is False is skipped, which is the goal of filtering unwanted elements. The parameter iterable is an iterative object, such as a list, dictionary, string, or function object with an iterator. Parameter functions are a function that can input elements into the judgment and return values, and if this argument is null, the identity function identity is used by default as a default function.
When function is non-null, it is equivalent to generating an expression:
Item for item in Iterable if function (item))
When function is empty, it is equivalent to generating an expression:
Item for item in Iterable if item
Example:
#filter () L = List (filter (None, [0, 1, 2, 3]) print (l) A = [1,2,3,4,5,6,7]b = List (filter (lambda x:x > 5, a)) print (b )
The output results are as follows:
[1, 2, 3]
[6, 7]
Cai Junsheng qq:9073204 Shenzhen
Python standard library: Built-in function filter (function, iterable)