Fredrik Lundh wrote: > > I tried to clear a list today (which I do rather rarely, considering > > that just doing l = [] works most of the time) and was shocked, SHOCKED > > to notice that there is no clear() method. Dicts have it, sets have it, > > why do lists have to be second class citizens? > > because Python already has a perfectly valid way to clear a list, > perhaps ? > > del l[:]
Ok. That's pretty non-obvious but now that I've seen it I'll probably remember it. I did a stupid "while l: l.pop()" loop myself. > (lists are not mappings, so the duck typing argument don't really > apply here.) I was thinking of list as a "mutable collection", and clear() is certainly a very natural operation for them. -- http://mail.python.org/mailman/listinfo/python-list