List copying idiom was Re: [Python-Dev] implementation of copy standard lib

John Machin sjmachin at lexicon.net
Wed Aug 17 02:14:49 CEST 2005


Tom Anderson wrote:
> 
> When you say [:], do you mean that you copy lists like this:
> 
> l = someList()
> m = []
> m[:] = l
> 
> ?

Why not
m = L[:]
instead of
m = []; m[:] = L
???

> 
> That's what i've been doing. The other day, i realised that i could just 
> do:
> 
> l = someList()
> m = list(l)
> 
> The same works for copying dicts. Whilst it's still not utterly obvious 
> that what this is about is making a copy, it's more obvious, cleaner, 
> shorter and probably faster than the slice assignment, which is really 
> kludgy (almost intercalorific, in fact - or even perlish!).



More information about the Python-list mailing list