dynamic naming for hierarchical problem

xauau xauau at yahoo.com.au
Thu Aug 9 05:56:35 CEST 2001


Jeremy Jones <dnjjones at yahoo.com> writes:

> 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:

If I understand you correctly, a 'tree' is not only a good way of
presenting this info to the user, it's also a straightforward way of
representing it internally.

You could build a fairly data structure called Tree which stores
nodes. Each node could consist of a piece of data, a reference to its
parent node, and a reference to a list of child nodes. (Like a doubly
linked list, except that you'd have a list of children instead of a
single 'next' pointer).

I'll pause here for confirmation that this is what you're looking
for. Perhaps it isn't.







More information about the Python-list mailing list