Why are there no ordered dictionaries?
Christoph Zwerschke
cito at online.de
Tue Nov 22 14:12:39 EST 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:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
http://pleac.sourceforge.net/pleac_python/hashes.html#AEN250
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