how to clear up a List in python?

Duncan Smith buzzard at
Fri May 26 19:23:31 CEST 2006

chris brat wrote:
> Doesnt this do what the original poster is try accomplish?

Not what the OP asked for, no.  Clearing a list implies that list1
should still be bound to the same list (which might be important if
there are other names bound to the same list).  If it wasn't important
that it be bound to the same list then I would probably go with
linnorm's approach (which isn't really 'clearing' the list).

>>> list1 = [0,1,2,3]
>>> id(list1)
>>> del list1[:]
>>> list1
>>> id(list1)
10772728  # i.e. the same list
>>> list1 = [0,1,2,3]
>>> id(list1)
>>> list1 = []
>>> id(list1)
10603576  # i.e. a different list


More information about the Python-list mailing list