decouple copy of a list

Kushal Kumaran kushal.kumaran+python at gmail.com
Fri Dec 10 08:54:51 EST 2010


On Fri, Dec 10, 2010 at 7:18 PM, Dirk Nachbar <dirknbr at gmail.com> wrote:
> I want to take a copy of a list a
>
> b=a
>
> and then do things with b which don't affect a.
>
> How can I do this?
>

b = a[:] will create a copy of the list.  If the elements of the list
are references to mutable objects (objects of your own classes, for
example), you might take a look at copy.deepcopy.

-- 
regards,
kushal



More information about the Python-list mailing list