data structure

noro amit.man at gmail.com
Sun Sep 3 15:22:37 EDT 2006


Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
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:
"
ROOT={'factory1':FACTORY,'facory2':FACTORY,'linux':OS,'windows':OS}
FACTORY={'manager':EMPLOEY,'worker':EMPLOEY,'office':BUILDING,'......}
OS={'ver':VERSION,'problems':LIST,....}
"
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
object.

i'll appreciate any comment
amit




More information about the Python-list mailing list