Alter list items within loop

Brendan brendandetracey at yahoo.com
Thu Jun 11 14:54:57 EDT 2009


Can someone please explain what is happening in the output below? The
number 3 never gets printed. Does Python make a copy of a list before
it iterates through it?:
>>> e = range(1,5)
>>> for i in e:
	print i
	if i == 2 :
		e.remove(i)


1
2
4
>>> e
[1, 3, 4]



More information about the Python-list mailing list