dynamic naming for hierarchical data problem

gzeljko gzeljko at sezampro.yu
Thu Aug 9 00:01:24 EDT 2001


From: Jeremy Jones <dnjjones at yahoo.com>
> I want to be able to dynamically build a hierarchical
> set of data.  (Forgive me if I am not using the proper
> terminology or if what I mean by a term is completely
> different from what the rest of you mean by the same
> term.  I am still a very new newbie and am just
> converting to Python after a couple of years of perl.
> I will try to clarify what I mean.)  By hierarchical,
> I mean that there will be parent-child relationships
> and that the parents and children should be aware of
> one another in their respective relationships (i.e.
> the parent should be aware of its children and
> children should be aware of their parents).  By
> dynamic, I mean that the names in the set of data will
> very likely be extracted from a text file or entered
> in by a user at run time.  I also mean that the number
> of levels in the hierarchy will potentially be
> variable and will be defined at run time.  I would
> prefer this set of data to be contained in one object.
>  Right now, I have the following, which is a three
> tier set of dictionaries that are associated with each
> other:
> 

You can begin with:

class MyTree:
  def __init__(self):
    d = {}
  def append_children_to_parent(self, parent, ch_list):
    item = self.d.setdefault(parent,[])
    item += ch_list

gzeljko















More information about the Python-list mailing list