sorteddict PEP proposal [started off as orderedict]

thebjorn BjornSteinarFjeldPettersen at gmail.com
Tue Sep 25 13:35:03 EDT 2007


On Sep 25, 10:53 am, Mark Summerfield <m.n.summerfi... at googlemail.com>
wrote:
> Hi,
>
> Below is a PEP proposal for a sorteddict. It arises out of a
> discussion on this list that began a few weeks ago with the subject of
> "An ordered dictionary for the Python library?", and a similar one on
> the P3K mailing list with the subject "ordered dict for p3k
> collections?".
>
> If there is positive feedback I will submit the PEP to the reviewers,
> so if you think it is a good idea please say so. (I'm sure that if you
> _don't_ like it you'll tell me anyway:-)

I can't see much advantage over:

  for key in sorted(mydict):
      ...

A much simpler data-structure, that is also very useful, is a
dictionary that keeps insertion order -- it's also something that's a
tad bit more difficult to implement yourself than the above. My
personal implementation is documented at http://blog.tkbe.org/archive/python-property-set/
It's very tempting to add value access by numerical index (I did as
well), however I now think it's a mistake.

-1 from me.

-- bjorn







More information about the Python-list mailing list