Deeper copy than deepcopy

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Oct 27 20:22:03 EDT 2009


On Tue, 27 Oct 2009 15:16:15 -0700, Gary Herron wrote:

> Try this:
> 
> 
>  >>> d = [1,2,3]
>  >>> r = [[x for x in d] for i in range(3)]
>  >>> r[1][2] = 999
>  >>> r
> [[1, 2, 3], [1, 2, 999], [1, 2, 3]]


[x for x in d] is better written as d[:]


-- 
Steven



More information about the Python-list mailing list