-2
我很疑惑爲什麼下面的代碼沒有正確地彈出並擴展它標識的每個零的列表。檢測並將零移到列表的末尾
def move_zeros(array):
array.extend([array.pop(i) for i,x in enumerate(array) if x != 0 and x != False])
return array
類似的帖子,我的答案回顧: How to move zeros to the end of a list [closed]
不要更改要迭代的數組。 – spectras