dictionary with order?
Erik Max Francis
max at alcyone.com
Fri Mar 14 23:28:44 CET 2003
> Is it make sense to let a python dictionary arrange its items
> according to
> the order that an items be added in?
> for example, by add a new method "setorder" (d.setorder(1) or
> d.setorder(-1) for reverse order) to let mothods like keys(),
> items() return sequence with items order same to the order for these
> be added.
It might, but builtin dictionaries don't. Write your own wrapper class
that maintains a list of the keys and a dictionary, and does the
appropriate overriding of the dictionary-like methods so that it does
what you want.
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ There is nothing wrong with sobriety in moderation.
\__/ John Ciardi
Physics reference / http://www.alcyone.com/max/reference/physics/
A physics reference.
More information about the Python-list