for i in list - change a list inside a for loop?

Klaus Meyer km-news1 at onlinehome.de
Sat Mar 1 14:51:24 EST 2003


> Better read about it in the Language Reference,
> http://www.python.org/doc/current/ref/for.html

Example:

x=range(10)
for i in x:
	x.append(i)

Hm, the ref says:
The expression list is evaluated once

If this was true, shouldn't the example stop after 10 loops?
But this gives a nice endless loop and a growing and growing x ....

> Eh.. no need to search for the element in the list.
> This is painfully slow.
My example was a simplification. In real i need re and something else so i 
must iterate over all elements.

I think i make a new list similarly to that example, that Anton gave. This 
would be a clean solution, i think.

Thanks folks!

-- 
Gruß - regards Klaus :-)




More information about the Python-list mailing list