Delete all list entries of length unknown

r rt8396 at gmail.com
Mon Oct 5 05:47:34 CEST 2009


On Oct 4, 10:09 pm, flebber <flebber.c... at gmail.com> wrote:
> Hi
>
> Can someone clear up how I can remove all entries of a list when I am
> unsure how many entries there will be.

Sure...!

>>> a = range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> del a[0]
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> del a[-1]
>>> a
[1, 2, 3, 4, 5, 6, 7, 8]
>>> del a[:]
>>> a
[]

or you could simple say

>>> a = []

;-)



More information about the Python-list mailing list