On Fri, 14 Jan 2005, Terry Carroll wrote:
> > class _macroString(object): > > def __init__(self,s): > > self.macro=s > > self.list=self.macro.split("\n") > > 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. Hi Terry, The 'for' loop itself should be ok, as it isn't a change that causes elements to shift around. The Reference Manual tries to explain the issue on in-place list mutation here: http://docs.python.org/ref/for.html So as long as the structure of the list isn't changing, we should be ok to do mutations on the list elements. Best of wishes! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor