Python filter usage and pythonfilter usage
1 class filter (object) 2 | filter (function or None, iterable) --> filter object3 | 4 | Return an iterator yielding those items of iterable for which function (item) 5 | is true. if function is None, return the items that are true.
Filter reads all iterable items, determines whether these items are true for the function, and returns an iterator containing all the real items. If the function is None, a non-empty item is returned.
1 In [2]: import re2 In [3]: I = re. split (',', "123, 123213, 123213,") 3 In [4]: i4 Out [4]: ['20140901 ','', '123', '','', '123', '']
In this case, list I contains an empty string.
1 In [7]: print (* filter (None, I) 2 123 123213 123213
In this case, the filter filters out the empty strings in the list to obtain an iterator containing only non-empty strings.
In [9]: print (list (filter (lambda x: x = '', I) ['', '']
Since lambda is true for empty strings, filter filters out non-empty strings, leaving only empty strings.