Delete all list entries of length unknown

r rt8396 at gmail.com
Sun Oct 4 23:47:34 EDT 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