python删除数组中元素

有数组a,要求去掉a所有为0的元素

a = [2,4,0,8,9,10,100,0,9,7]

  1. Filter
    a= filter(None, a)

  2. Lambada
    a = filter(lambda x: x != 0, a)

  3. for
    for b in a:
    if b == 0:
    a.remove(b)

原文地址:https://www.cnblogs.com/james0/p/7993444.html