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', ' ']))
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', ' ']))