Pop a list from beginning ? and memory saving...

Peter Hansen peter at engcorp.com
Wed Jun 5 16:40:34 CEST 2002


Jeff Epler wrote:
> 
> On Tue, Jun 04, 2002 at 11:36:39PM -0400, Peter Hansen wrote:
> (speaking about this expression):
> >> l[:] = []
> >
> > Oh, and in my opinion, that is obscure and deserves a
> > comment explaining how it works, and why it is being done.
> > I might not feel that way if I write that idiom a few times,
> > though. :)
> 
> IMO
>     del l[:]
> is clearer than
>     l[:] = []
> I'd accept the first one immediately, and puzzle over the second one for
> a short (or even long) time.

Agreed, although my brain knows that "x = l[:]" is the idiom
for making a copy of a list, so it wants to tell me that "del l[:]"
is just going to make a copy, then delete it right away.

-Peter



More information about the Python-list mailing list