让我们假设,
g = ['1', '', '2', '', '3', '', '4', '']
我想从 g 中删除所有 ''
,我必须从那里获取
g = ['1', '2', '3', '4']
>>> g = ['1', '', '2', '', '3', '', '4', '']
>>> filter(None, g)
['1', '2', '3', '4']
Help on built-in function filter in module `__builtin__`:filter(...)filter(function or None, sequence) -> list, tuple, or string Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list.
You can also use a list comprehension if you prefer
>>> [x for x in g if x!=""]
['1', '2', '3', '4']
我是一名优秀的程序员,十分优秀!