https://www.programiz.com/python-programming/methods/built-in/filter

The filter() method constructs an iterator from elements of an iterable for which a function returns true.

filter()方法语法:

filter(function, iterable)

参数:

function - function that tests if elements of an iterable returns true or false. If None, the function defaults to Identity function - which returns false if any elements are false.

iterable - iterable which is to be filtered, could be sets, lists, tuples, or containers of any iterators.

返回值:

The filter() method returns an iterator that passed the function check for each element in the iterable.

filter()方法等价于:

# when function is defined
(element for element in iterable if function(element))

# when function is None
(element for element in iterable if element)

posted on 2019-07-29 18:00  03221053  阅读(265)  评论(0编辑  收藏  举报