I have written a simple python program
l=[1,2,3,0,0,1]
for i in range(0,len(l)):
if l[i]==0:
l.pop(i)
This gives me error 'list index out of range' on line if l[i]==0:
After debugging I could figure out that i
is getting incremented and list is getting reduced.
However, I have loop termination condition i < len(l)
. Then why I am getting such error?