Ordered dict by default

Stephen Hansen apt.shansen at gmail.com
Thu Feb 5 11:05:19 EST 2009


> Now, I also do recognize the utility of ordered dictionaries in some cases, but
> exactly what you mean by ordered varies. I have two cases where "ordered"
> has the keys are in a specific custom order. I have four cases where "ordered"
> means maintaining insertion order. For the former I do sorted(dict) on access
> when I need to do something order-related. For the latter I have a simple
> ordered dictionary implementation that maintains the keys as a separate list
> attached to the dictionary.

Ooh, as an addendum... I found one case where I want insertion-and-update
order: meaning that its an ordered dictionary that maintains insertion
order, but
an update to a particular item moves that item to the back so an update behaves
like del d[key]; d[key] = value in terms of the key order.

"Ordered Dictionaries" are a bit fuzzy. :)

--S



More information about the Python-list mailing list