[Python-3000] ordered dict for p3k collections? (original) (raw)

Mark Summerfield mark at qtrac.eu
Tue Sep 25 23:01:43 CEST 2007


On 2007-09-25, you wrote:

On 9/25/07, Mark Summerfield <mark at qtrac.eu> wrote: > My proposal was for the sorteddict to be put in the collections module, > not as a builtin. One of the things I particularly like about Python is > that the core language is small. > > However, I think that the collections module is rather thin, and as you > say, it is "obscure" so won't get in the way of inexperienced or casual > users if it is beefed up a bit, yet could be really useful to more > demanding users. > > On comp.lang.python, a respondent called Paul Hankin suggested a > somewhat different approach to mine: he proposed a sorteddict with the > same API as a dict but with a constructor that is similar to the > sorted() function: > > sorteddict((mapping | sequence | nothing), cmp=None, key=None, > reverse=None) > > He points out that this has a problem with keyword argument > dictionaries, but that one solution is sorteddict(dict(**kwargs), ...).

Why would this be a problem? There is no requirement that sorteddict() support this feature. > From comments other people have made on this list and on > comp.lang.python, it may be that Paul Hankin's approach is more popular > and better than the one I proposed---the only downside being that he > didn't give any hints as to an implementation. > > I am hoping that Python 2.6 (and 3.0) will have a sorted dictionary of > some kind, and I get the impression that it would be welcomed (in the > standard library). For that to happen, someone has to write a production-quality implementation, release it as a separate 3rd party module for a while, show that it is sufficiently stable and popular to be incorporated in the standard library, and commit to maintaining it for a few years at least. (It doesn't have to be all the same someone.)

OK, I'm sure I or Paul Hankin or others will put up at least one version on PyPI and maybe get it in for Python 4:-)

Hoping and wishing doesn't cause working code to spring into existence.

As a matter of fact it does... by the time I read this Paul Hankin had written a version based on his idea... and so have I. Neither is likely to be fast but they both provide the API described above in pure Python.

-- Mark Summerfield, Qtrac Ltd., www.qtrac.eu



More information about the Python-3000 mailing list