Deeper copy than deepcopy

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Oct 28 01:22:03 CET 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