python2中过滤器 filter的使用
Posted 那时的吻狠陶醉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\', \' \']))
![](https://image.cha138.com/20210602/83d91b43314b46cc814375e99018efe0.jpg)
以上是关于python2中过滤器 filter的使用的主要内容,如果未能解决你的问题,请参考以下文章