stupid/style/list question

Fredrik Lundh fredrik at pythonware.com
Tue Jan 8 10:45:01 EST 2008


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>




More information about the Python-list mailing list