s = ['123', '', '\t', '\n', 'qweq']
将s里面的'','\t','\n'去掉:
filter(str.strip,s)
输出结果:
注意:这里得是python2python3的话可以这样:
def not_empty(s): return s and s.strip() list(filter(not_empty, ['A', '', 'B', None, 'C', ' ']))