python2中过滤器 filter的使用

s = ['123', '', '\t', '\n', 'qweq']

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

  输出结果:

 

注意:这里得是python2


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

list(filter(not_empty, ['A', '', 'B', None, 'C', '  ']))

 

 
posted @ 2018-02-27 15:03  那时的吻狠陶醉  阅读(951)  评论(0编辑  收藏  举报