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

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

  输出结果:

python2中过滤器 filter的使用

 

注意:这里得是python2


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

list(filter(not_empty, ['A', '', 'B', None, 'C', '  ']))
python2中过滤器 filter的使用

 

 

相关文章:

  • 2021-11-19
  • 2021-12-03
  • 2021-11-29
  • 2021-12-04
  • 2021-11-19
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-05-01
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案