Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Thu Nov 24 11:37:06 EST 2005


Fuzzyman wrote:

> You will be able to mutate the the keys list through :
> 
> d1 = OrderedDict(some_sequence_of_items)
> keys = d1.keys()
> keys.sort() # or other mutation
> d1.keys(keys)
> 
> Admittedly this is a lot slower than :
> 
> d1 = OrderedDict(some_sequence_of_items)
> d1.sequence.sort()
> 
> *but* it frees the squence attribute from any implementation details.

You should also implement

d1.sort() or d1.sortkeys()

which will have no performance drawbacks.

-- Christoph



More information about the Python-list mailing list