From: Bill Anderson [mailto:[EMAIL PROTECTED]]

>Is it more important that they be in an order, or that they be in a
>specific sequential list?

Actually what is important is that they are integers and in a specific
order. So the datestamp method isn't that feasible for me.

(I'm trying to make a "fake tree" for a diskussion product.)

It is really easy to implement and doesn't use recursion, so traversing the
tree is done with a simple for loop.

It uses a dictionary with tupples as keys to emulate the recursive
structure. Simple example here if anybody cares.


class fakeTree:
    def __init__(self):
        #create tree and insert root element
        self.treeKeys = {}
        self.treeKeys[0] = (0,)
        self.tree = {}
        self.tree[(0,)] = ''
    def insert(self, id, parent, value):
        # create new key
        keyList = list(self.treeKeys[parent])
        newKeyList = keyList.append(id)
        newKeyTuple = tuple(newKeyList)
        self.treeKeys[id] = newKeyTuple
        # insert in tree with new tuple key
        self.tree[newKeyTuple] = value

    def print(self):
        sortedKeys = treeKeys.keys()
        spacesInIndent = 3
        for key in sortedKeys:
            print key
            print spacesInIndent * len(key) * ' ' + treeKeys[key]

tree = fakeTree()
tree.insert(1, 0, 'max m')
tree.insert(2, 0, 'gitte')
tree.insert(3, 1, 'magnus')

Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to