[Tutor] file-like object

Alan Gauld alan.gauld at freenet.co.uk
Sat Jan 15 01:41:02 CET 2005


> >         for n,v in enumerate(self.list):
> >             self.list[n]=v+'\n'
>
>
> Is this for loop a safe technique, where the list you're enumerating
over
> in the for statement is the same as the one being updated in the
loop
> body?  I always avoid things like that.

Its not changing the list, its changing the list contents.
If it were adding or re,moving items from the list that
would be dodgy, but modifying a existing element doesn't
really change the list itself in any significant way.

Alan G.



More information about the Tutor mailing list