stupid/style/list question

Giampaolo Rodola' gnewsg at gmail.com
Tue Jan 8 14:05:12 EST 2008


On 8 Gen, 16:45, Fredrik Lundh <fred... at pythonware.com> wrote:
> Giampaolo Rodola' wrote:
> > To flush a list it is better doing "del mylist[:]" or "mylist = []"?
> > Is there a preferred way? If yes, why?
>
> The latter creates a new list object, the former modifies an existing
> list in place.
>
> The latter is shorter, reads better, and is probably a bit faster in
> most cases.
>
> The former should be used when it's important to clear a specific list
> object (e.g. if there are multiple references to the list).
>
> </F>

I'm going to use the latter one, thanks.



More information about the Python-list mailing list