有数组a,要求去掉a所有为0的元素
a = [2,4,0,8,9,10,100,0,9,7]
- Filter
a= filter(None, a)
- Lambada
a = filter(lambda x: x != 0, a)
- for
for b in a:
if b == 0:
a.remove(b)
时间: 2024-10-19 16:59:53
a = [2,4,0,8,9,10,100,0,9,7]
a= filter(None, a)
a = filter(lambda x: x != 0, a)
for b in a:
if b == 0:
a.remove(b)