I tried to run the following python code, but I'm constantly getting "IndexError: list index out of range". I'm pretty sure that all the 'i' values are within the range of the list, I verified it by printing them at each iteration. I need help debugging it. Thanks!
list = [1, 2, 4, 0, 0, 7, 5]
new_list = []
length = len(list)
for i in range(length):
if list[i] == 0 or list[i] == 7:
list.pop(i)
new_list.append(list[i])
else:
pass
print(new_list)