#把列表中的0全部移到后面,非零元素出现的顺序不变,要求在原列表上进行.
lst1 = [0, 0, 0, 0, 18754, 0, 0, 0, 0, 0, 0, 13, 1, 0, 1, 5, 0, 6, 0, 1, 9, 1, 2, 3, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
length = len(lst1)
for k in range(length):
for i in range(length-1):
if lst1[i] == 0:
lst1[i], lst1[i+1] = lst1[i+1], lst1[i]
print(lst1)
#[18754, 13, 1, 1, 5, 6, 1, 9, 1, 2, 3, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]