How can i remove elements with a value of 0 as they pop upp in this loop?
y = [4, 2, 7, 9] x = input("run?") while x: for i in range(len(y)): y[i] -= 1 y.append(len(y)) print(y) you could always use a list comprehension to filter them:
for i in range(len(y)): y[i] -= 1 y = [x for x in y if x != 0] # <-- added here y.append(len(y)) EDIT:
I'm silly - these operations could even be combined as so:
while whatever: #<-- fix as suggested by comment on your question y = [z-1 for z in y if z > 1] y.append(len(y)) y = filter(lambda i: i != 0, y)
while xwill put you into an infinite loop ifxevaluates toTrue