Python filter () method

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 () method syntax:

filter(function, iterable)

parameter:

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.

return value:

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

filter () method is equivalent to:

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

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

Guess you like

Origin www.cnblogs.com/wufan03221053/p/11264884.html