list.clear() missing?!?

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 11 13:19:15 EDT 2006


Ville Vainio wrote:
> It's just that, when I have an object, and am wondering how I can clear
> it, I tend to look what methods it has first and go to google looking
> for "idioms" second.

I guess del on a list is not that common, so people tend to not know
that it works on lists (and slices!), too. It's too bad that lists have
a pop() method these days, so people can do x.pop() even if they don't
need the value, instead of doing del x[-1]. I don't think I ever needed
to del a slice except for clearing the entire list (and I don't need to
do that often, either - I just throw the list away).

Regards,
Martin



More information about the Python-list mailing list