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://images2018.cnblogs.com/blog/1126801/201803/1126801-20180307152049792-382330774.png)
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://images2018.cnblogs.com/blog/1126801/201803/1126801-20180307152049792-382330774.png)