Ordered Dictionaries? Trees?

Rainer Deyke root at rainerdeyke.com
Mon Sep 4 23:39:07 CEST 2000


"Stephen Hansen" <stephen at cerebralmaelstrom.com> wrote in message
news:20000904.133113.2838 at Jeremy.cerebralmaelstrom.com...
> I need a Dictionary who's order is perdictable and/or settable; e.g.
> FIFO/LILO... For instance, if I do: dict['A'] = 1, dict['C'] = 2,
dict['B'] = 3,
> then dict.keys() would return ('A','C','B'), always. :)
>
> Each value would prolly be another one of these dictionaries, so what
> i'd be doing is setting up a tree-structure. What's the best way to do
this,
> that isn't tooooooo terribly slow? Speed isn't urgent, but hey, i'd rather
> it not become a negative later on as things expand.

Subclass UserDict.  Override __set_item__ to also append the key to an
internal list.  Override keys to return the list.  If you also want to
remove or replace dictionary items, thing become slightly more complicated,
but the same principles apply.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list