how to clear up a List in python?

Duncan Smith buzzard at urubu.freeserve.co.uk
Fri May 26 18:24:50 CEST 2006


linnorm at gmail.com wrote:
> The original post only mentions deleting the values in the list, not
> the list itself.  Given that you want to keep the list and just ditch
> the values it contains I'd go with:
> 
> list1 = []
> 
> -Linnorm
> 

Which rebinds list1 to a new (empty) list.  It doesn't clear the
original list (which appears to be what the OP wants).

>>> list2 = [0,1,2,3,4,5]
>>> list1 = list2
>>> list1 = []
>>> list2
[0, 1, 2, 3, 4, 5]
>>>

Duncan



More information about the Python-list mailing list