Re: Storing and searching nodes of a tree

2007-05-15 Thread [EMAIL PROTECTED]
On May 15, 9:25 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, > > [EMAIL PROTECTED] wrote: > > If I have the tree in the dictionary, the code would like this, > > def search(tree, path): > >while path and not(tree.haskey(path)): > > path = path[:-1]

Re: Storing and searching nodes of a tree

2007-05-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > If I have the tree in the dictionary, the code would like this, > def search(tree, path): >while path and not(tree.haskey(path)): > path = path[:-1] >if path: > return tree[path] >else: > raise KeyError('path

Re: Storing and searching nodes of a tree

2007-05-15 Thread [EMAIL PROTECTED]
On May 15, 6:33 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, > > > > [EMAIL PROTECTED] wrote: > > I use these names as keys in a dictionary, and store node's data. > > Now given a name like "abc", I want to find the key with the following > > rule: > > If the ke

Re: Storing and searching nodes of a tree

2007-05-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > I use these names as keys in a dictionary, and store node's data. > Now given a name like "abc", I want to find the key with the following > rule: > If the key exists return the value > If the key does not exist, return the value of the leaf node