1. 程式人生 > >python刪除數組中元素

python刪除數組中元素

python == amba none class 元素 mark down 要求

有數組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)

python刪除數組中元素