Why are there no ordered dictionaries?

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Nov 20 16:34:17 EST 2005


[restored my attribution line so we know who said what]

Christoph Zwerschke <cito at online.de> wrote:
> Ben Finney wrote:
> > In what cases do you find yourself needing a dict that preserves
> > its key order? Can you present a use case that would be improved
> > by an ordered dict?
> 
> There are too many different situations and it would be too much to
> explain them here, usually in the case mentioned above where the
> keys are not sorted alphabetically.

Without an example, it's hard to know what you want to do and whether
an ordered dictionary is the best way to do it.

> > For my part, I consider it a virtue of Python that the standard
> > library doesn't change rapidly. It allows many competing
> > implementations to be shaken out before everyone starts depending
> > on any one of them.
> 
> Ok, but this can be used as an argument to not add anything to the
> standard lib any more.

I hope not. Rather, it's an argument not to add something to the
standard library until it's proven (to the BDFL's criteria) that it's
better in than out.

> There are already enough competing 
> implementations.

Have they been sufficiently shaken out to show a clearly superior
version? Is any version sufficiently beneficial to write a PEP for its
inclusion in the standard library?

> I simply wanted to ask why it is not available in the standard lib,
> since I simply don't know
> 
> - has it not been demanded loud enough?

Loud demands don't count for much. PEPs with popular working
implementations do.

> - is it really not needed (if you need it it shows you are doing
> something wrong)?

You dismissed a request for your use cases with handwaving. How can we
know?

> - because nobody presented a satisfying implementation yet?

I'm not sure what you mean by "satisfying".

> - are there hidden difficulties or controversial issues?

Another possibility: ordered dictionaries are not needed when Python
2.4 has the 'sorted' builtin.

-- 
 \       "Those who will not reason, are bigots, those who cannot, are |
  `\     fools, and those who dare not, are slaves."  -- "Lord" George |
_o__)                                                Gordon Noel Byron |
Ben Finney



More information about the Python-list mailing list