python2中过滤器 filter的使用

s = ['123', '', '	', '
', 'qweq']

将s里面的'',' ',' '去掉:
filter(str.strip,s)

  输出结果:

注意:这里得是python2


python3的话可以这样:
def not_empty(s):
    return s and s.strip()

list(filter(not_empty, ['A', '', 'B', None, 'C', '  ']))
 
原文地址:https://www.cnblogs.com/fh-fendou/p/8478970.html