style question: how to delete all elements in a list

gry at gry at
Mon Mar 6 22:25:05 EST 2006

Just curious about people's sense of style:

To delete all the elements of a list, should one do:

   lst[:] = []

I seem to see the first form much more often in code, but
the second one seems more clearly *deleting* elements,
and less dangerously mistaken for the completely different:
   lst = [] 

What do you think?

-- George Young

More information about the Python-list mailing list