data structure

noro at
Sun Sep 3 21:22:37 CEST 2006

Hello again.

I have a task i need to do and i can't seem to find an elegent
i need to make a tree like data structure (not necessry a binary tree).

i would like each node to access his sons in a dicionary kind of why,
for example: if  ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
i started bulding the class NODE as an extention of  "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an

i'll appreciate any comment

More information about the Python-list mailing list