Why are there no ordered dictionaries?
Carsten Haese
carsten at uniqsys.com
Wed Nov 23 20:07:41 EST 2005
On Wed, 23 Nov 2005 23:39:22 +0100, Christoph Zwerschke wrote
> Carsten Haese schrieb:
>
> > Thus quoth the Zen of Python:
> > "Explicit is better than implicit."
> > "In the face of ambiguity, refuse the temptation to guess."
> >
> > With those in mind, since an odict behaves mostly like a dictionary, []
> > should always refer to keys. An odict implementation that wants to allow
> > access by numeric index should provide explicitly named methods for that
> > purpose.
>
> Exactly. But I don't think in this case such methods would be
> needed. You easily get the i-th value in the ordered dict as
> d.values()[i].
>
> -- Chris
True enough, but unless the odict has its list of values on hand, you're
asking the odict to build a list of all its values just so that you can get
the i'th element. Having a method that does the equivalent of d[d.sequence[i]]
would be cleaner and more efficient.
-Carsten
More information about the Python-list
mailing list