Python built-in function - filter
##filter
filterfilter(function, iterable)
Copy after login
This function is used to traverse all elements from an iterable object iterable. When each After the elements are given as parameters to the function object, the elements judged to be True are retained, while the elements judged to be False are skipped, which is to achieve the goal of filtering unnecessary elements. The parameter iterable is an iterable object, such as a list, dictionary, string, or function object with an iterator. The parameter function is a function that can input elements for judgment and return a value. If this parameter is empty, the identity function will be used as the default function by default.
When function is non-empty, it is equivalent to generating an expression:
item for item in iterable if function(item))
当function为空时,相当于生成表达式:
item for item in iterable if item
>>> l = list(filter(None,[0,1,2,3]))
>>> l
[1, 2, 3]
>>> l = list(filter(lambda x: x>5,range(10)))
>>> l
[6, 7, 8, 9]
Copy after login
The above is the content of Python's built-in function - filter. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!