List problem

Batista, Facundo FBatista at uniFON.com.ar
Fri Oct 29 20:19:29 CEST 2004


[Thomas M.]

#- test_list = [1, 2, 3]
#- 
#- for i in test_list:
#-    print i
#- 
#-    if 1 in test_list:
#-       test_list.remove(1)

As a rule of thumb, never modify a list that you're iterating.

If you want to modify the list, iterate a copy:

for i in test_list[:]:
	...


.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041029/b34fb9f3/attachment.html>


More information about the Python-list mailing list