Why are there no ordered dictionaries?
carsten at uniqsys.com
Thu Nov 24 02:07:41 CET 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
> -- 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.
More information about the Python-list