Pop a list from beginning ? and memory saving...
Peter Hansen
peter at engcorp.com
Tue Jun 4 23:36:39 EDT 2002
Peter Hansen wrote:
>
> Terry Reedy wrote:
> > >>> l
> > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> > >>> l[:] = []
> > >>> l
> > []
>
> I must have missed the _why_ part... ah! enlightenment:
> you are removing the contents of the list, which might
> have other references to it, rather than rebinding the name
> self._v to a new empty list but leaving those other
> references alone.
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. :)
-Peter
More information about the Python-list
mailing list