Why are there no ordered dictionaries?
Aahz
aahz at pythoncraft.com
Mon Nov 21 13:04:37 EST 2005
In article <1h6c6t4.1hc5owk13rgcrhN%aleax at mail.comcast.net>,
Alex Martelli <aleax at mail.comcast.net> wrote:
>
>I think you're wrong here. People in the past who have requested or
>implemented stuff they called 'ordered dicts' in the past had in mind
>drastically different things, based on some combination of insertion
>orders, keys, and _values_. So, ambiguity is definitely present in the
>phrase 'ordered dictionary', because there are so many different
>criteria whereby the 'ordering' could take place.
>
>Note the plural in 'insertion orderS': some people care about the FIRST
>time a key was added to a dict, some about the LAST time it was added,
>some about the latest time it was 'first inserted' (added and wasn't
>already there) as long as it's never been deleted since that occasion --
>and these are just a few of the multifarious orders based on the time of
>insertions and deletions of keys.
Ayup. In our application, not only do we have ordered dicts, we also
have something called a "sectioned dict", which is a dict-like object
that also looks like a regular class instance with attribute access. The
section part actually has multiple dicts (the sections) which are
layered, so that a dict key in the top layer overrides the value of the
key in lower layers. We traditionally have used it such that the
sections are accessed in MRU orders; last week, we added a new feature
that allows setting section values without changing section order (to
allow setting a default, essentially).
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur." --Red Adair
More information about the Python-list
mailing list