Proposed implementation for an Ordered Dictionary

Raymond Hettinger python at rcn.com
Thu Feb 26 17:57:26 EST 2009


[Hrvoje Niksic]
> It seems that __delitem__ of an existing key is O(n), whereas it's
> amortized constant time for dicts.  (__setitem__ is constant time for
> both.)  Is there a way to avoid this?

I don't see any fast/clean way.  It's possible to tracking pending
deletions
and do them all at once but that's a bit messy and slow.


> If not, it should probably be documented, since it differs from dict.

That makes sense.


Raymond




More information about the Python-list mailing list