Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

question about tree in python

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


"knutjbj(nospam)" at online

Nov 18, 2009, 8:48 AM

Post #1 of 2 (130 views)
Permalink
question about tree in python

How should I write a tree using diconary. I have used a dictonary to
make a tree.

tree={best:collections.defaultdict(lambda:default)} in a id3 tree.

Is there a way to multple values and when then only return on type of
values.

I tried this apporach but it did not work.

class Tree:
def __init__(self):
pass



def ini(self,default_tree,d_attr):
self.tree={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_A={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_I={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_p={d_attr:collections.defaultdict(lambda:default_tree)}
self.tree_n={d_attr:collections.defaultdict(lambda:default_tree)}
return self.tree

def __call__(self,best,val,subtree):
self.tree[best][val]=subtree

def
input_tree(self,best,val,subtree,postive,negative,attribute_value,info_gain):
tree=self.tree
print best
print val
tree[best][val]=subtree
print self.tree
self.tree_A[best][val]= attribute_value
self.tree_I[best][val]= info_gain
self.tree_p[best][val]= postive
self.tree_n=negative
tree=self.tree
return tree
--
http://mail.python.org/mailman/listinfo/python-list


lie.1296 at gmail

Nov 18, 2009, 2:01 PM

Post #2 of 2 (121 views)
Permalink
Re: question about tree in python [In reply to]

nospam wrote:
> How should I write a tree using diconary. I have used a dictonary to
> make a tree.

dictionary tree?

root = {
'node_a': {
'node_a_a': 'blah',
'node_a_b': 'foo',
'node_a_c': 'bar',
},
'node_b': {
'node_b_a': 'soo',
'node_b_b': 'flee',
'node_b_c': {
'node_b_c_a': 'bee',
'node_b_c_b': 'fee',
'node_b_c_c': 'dee',
},
},
}

you can throw in some default dicts as well as necessary...

Am I misunderstanding something?
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.