所以我有一些代码:
nlist = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,2,0]
count = 0
for i in nlist:
if nlist[i] == 0:
nlist.remove(nlist[i])
count += 1
if count == 4:
count = 0
print(nlist)
当我运行它时,输出为:
[0, 0, 0, 0, 0, 0, 2, 0]
即使输出应该是这样:
[2]
有人可以告诉我我做错了什么吗?