Why are there no ordered dictionaries?

Fredrik Lundh fredrik at pythonware.com
Mon Nov 21 10:12:29 CET 2005


bonono at gmail.com wrote:

> If I need the dict feature 90% of the time, and the list feature 10% of
> the time.

Wasn't your use case that you wanted to specify form fields in
a given order (LIST), render a default view of the form in that
order (LIST), and, later on, access the field specifiers in an
arbitrary order, based on their key (DICT).  Sure looks like it's
the LIST aspect that's important here...

("but assume that I have some other use case" isn't a valid use
case)

> I want an ordered dict. Rather than a list and create this new view every
> time and every where I want to use it as a dict.

You want an ordered dict because you say you want one, not be-
cause it's the best way to address your use case.  That's fine, but
it's not really related to the question asked in the subject line.

> parsing or not parsing is not the point, and parsing/converting is
> still "create a new view" of an existing data structure.

Copying the entire data structure hardly qualifies as "creating a
new view".  dict() doesn't do that; in this use case, it doesn't cost
you anything to use it.

Everything has a cost in Python.  Things aren't free just because
they're implemented by some other module.

But when things are free, they're often a good choice.

</F>






More information about the Python-list mailing list