Best way to create a copy of a list

Paul Rubin http
Tue Apr 4 17:50:19 EDT 2006


aleaxit at yahoo.com (Alex Martelli) writes:
> I vastly prefer to call list(xxx) in order to obtain a new list with the
> same items as xxx -- couldn't be more obvious than that.
> 
> You can't claim it's obvious that xxx[:] *copies* data

Heh, it wasn't obvious that list(xxx) copies data either (I thought of
it as being like a typecast), but I just checked, and it does copy.
I'll have to remember to do it like that.  I do like it better than
xxx[:] which is what I'd been using because I remember seeing that the
copy module does it that way.



More information about the Python-list mailing list