Another dict method...

Tim Peters tim.one at home.com
Sat May 19 01:34:30 EDT 2001


[Emile van Sebille, about the 2.2 dict.iteritems() iterator]
> Yes.  Can it retrieve them in sorted order?

No.  The order of retrieval is undefined.  It's not magic, it's fast <wink>.
The only sort gimmick of any kind in the language is list.sort().

> I also see a clear method.  Is there an advantage in using it over simply
> reassigning to a new {} ?

dict.clear() clears the dict in-place, without creating a new object.
Whether that's what you want depends on whether you want aliases (other ways
of getting to the object besides via the name "dict") to see the effect of
the clear too.






More information about the Python-list mailing list