Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Tue Nov 22 20:12:39 CET 2005

Bengt Richter wrote:
> After finally reading that the odict.py in PyPI by Larosa/Foord was what was desired,
> but slower in use than what Fredrik posted, I decided to see if I could speed up odict.py.
> I now have a version that I think may be generally faster.

Hm, I wouldn't formulate it that way that I want the odict of 
Larosa/Foord, but I want "the one" "obvious" odict for which 
Larosa/Foord have already made one implementatin ;-)

Others are here:

It is all essentially the same idea I think (though after having a 
closer look I see implementation shortcomings in all of them).

 > I now have a version that I think may be generally faster.

Great. I also wanted to do that. Also, I would like to add some 
functionality to Larosa/Foord's odict, like creating or updating an 
odict from an ordinary dict (keys taken over from the ordinary dict will 
be either in random order or automatically sorted). An ordered 
dictionary should also have methods for sorting (like PHP's ksort()).
This way, you could initialize an ordered dict from an ordinary dict, 
sort it, and from then on never care to call keys().sorted() or 
something when iterating over the dictionary. Probably there are other 
methods from lists that could be taken over to ordered dicts.

-- Christoph

More information about the Python-list mailing list