Why does python behave so? (removing list items)

Thomas Dybdahl Ahle lobais at gmail.com
Wed Mar 26 18:12:27 EDT 2008


On Wed, 2008-03-26 at 23:04 +0100, Michał Bentkowski wrote:
> Why does python create a reference here, not just copy the variable?

Python, like most other oo languages, will always make references for =,
unless you work on native types (numbers and strings).

Instead use one of:
k = j[:]
or
k = [i for i in j]
or
from copy import copy
k = copy(j)
or
k = range(6)

-- 
Best Regards,
Med Venlig Hilsen,
Thomas




More information about the Python-list mailing list