Novice [].append Help

waters waters at porkless.net
Tue Mar 2 10:21:59 EST 2004


John Roth wrote:
> You've fallen into one of the little traps. There's only *one*
> copy of the l_format list, and it's being bound to l_local each
> time through the loop. Assignment is *not* creating a copy of
> the l_format list; it's reusing it, so each slot in the l_output list
> is pointing to the *same* list, which of course contains the last
> value you put into it.
> 
> If you change the 4th line to:
> 
> l_local = list(l_format)
> 
> it will work because the list type will produce a copy.
> 
> John Roth

Thanks for this, and all subsequent replies. Will keep an eye out for 
these (coder-induced) assignment issues.



More information about the Python-list mailing list