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?
range(len(l))
, as 0 is the default starting value.l
(lowercase letter el),O
(uppercase letter oh), orI
(uppercase letter eye) as single character variable names. python.org/dev/peps/pep-0008range(0,len(l))
has a result that varies whenl
is changed? Why do you think that? Where did you read it?