Why are there no ordered dictionaries?

Fuzzyman fuzzyman at gmail.com
Mon Nov 21 16:01:16 CET 2005


Fredrik Lundh wrote:
> Ben Sizer wrote:
>
> > > No, that's not the same logic.  The dict() in my example doesn't convert be-
> > > tween data types; it provides a new way to view an existing data structure.
> >
> > This is interesting; I would have thought that the tuple is read and a
> > dictionary created by inserting each pair sequentially. Is this not the
> > case?
>
[snip..]
> (as an example, on my machine, using Foord's OrderedDict class
> on Zwerschke's example, creating the dictionary in the first place
> takes 5 times longer than the index approach, and accessing an
> item takes 3 times longer.  you can in fact recreate the index 6
> times before OrderedDict is faster; if you keep the index around,
> the OrderedDict approach never wins...)
>

So, so long as you want to use the dictionary less than six times -
it's faster to store/access it as a list of tuples. ;-)

Everytime you want to access (or assign to) the data structure as a
dictionary, you have to re-create the index.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> </F>




More information about the Python-list mailing list