1 class Filter (object) 2 | or None, Iterable)-- Filter Object3 | 4 | for which function (item) 5 | is is return The items that is true.
Filter reads all the items in the iterable, determines whether the keys are true for the function, and returns an iterator that contains all the items that are true. If function is None, returns a non-empty item.
1In [2]:ImportRe2In [3]: i = re.split (',',"123,,123213,,, 123213,")3in [4]: I4OUT[4]: ['123',"','123213',"',"','123213',"']
In this case, the list I contains an empty string.
1 Print (*filter (None, i)) 2 123 123213 123213
The filter then filters out the empty string in the list and gets an iterator containing only the non-empty string.
Print (List (filter (lambda x:x==', i))) [""]
Because Lambda is true to an empty string, filter filters out non-empty strings, leaving only empty strings.
Python Filter Usage