Question about idioms for clearing a list

Fredrik Lundh fredrik at pythonware.com
Mon Feb 6 13:25:44 EST 2006


Peter Hansen wrote:

> > Perhaps it is arguable that there is no need for a clear method because
> > L[:] = [] is so easy to do. Personally, while I agree that it is easy, it
> > is hardly intuitive or obvious, and I too would prefer an explicit clear
> > method for mutable sequences.
>
> Possibly another case where "patches are welcome"...

so we can have three ways to do the same thing?  the right way to
nuke a sequence is to do "del L[:]".  this is explained in Python 101.

(del doesn't work on dictionaries)

</F>






More information about the Python-list mailing list