Why are there no ordered dictionaries?

Alex Martelli aleax at mail.comcast.net
Wed Nov 23 00:48:35 EST 2005


bonono at gmail.com <bonono at gmail.com> wrote:

> Bengt Richter wrote:
> > For me the implication of "sorted" is that there is a sorting algorithm
> > that can be used to create an ordering from a prior state of order,
> > whereas "ordered" could be the result of arbitrary permutation, e.g.,
> > manual shuffling, etc. Of course either way, a result can be said
> > to have a particular defined order, but "sorted" gets ordered
> > by sorting, and "ordered" _may_ get its order by any means.
> >
> But Alex seems to think that based on another external table should be
> classified as "sorted" whereas I would consider it as "manual
> shuffling", thus "ordered".
> 
> I may be wrong it interpreting him though, which is why I want to
> clarify.

What you can obtain (or anyway easily simulate in terms of effects on a
loop) through an explicit call to the 'sorted' built-in, possibly with a
suitable 'key=' parameter, I would call "sorted" -- exactly because, as
Bengt put it, there IS a sorting algorithm which, etc, etc (if there
wasn't, you couldn't implement it through the 'sorted' built-in!).

So, any ordering that can be reconstructed from the key,value data held
in a dict (looking up some combinations of those in an external table is
nothing special in these terms) falls under this category.  But, a dict
does not record anything about what was set or changed or deleted when;
any ordering which requires access to such information thus deserves to
be placed in a totally separate category.


Alex



More information about the Python-list mailing list