There a many ways to do this, here's one:
from collections import namedtuple
Tree = namedtuple('Tree', ['feature', 'children'])
t = Tree(1, [Tree('hello', []), Tree(3, [])])
--
http://mail.python.org/mailman/listinfo/python-list
couple of links for python tree:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/217212
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/201423
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305313
http://www.rexx.com/~dkuhlman/
--
http://mail.python.org/mailman/listinfo/
vivek khurana wrote:
i am a new member on this list. I have to implement
tree data structure using python. How it can be done
in python. Is there an existing data structure which
can be used as tree? I have searched archives and
manuals but no luck.
You can start with Guido's essay
http://python
Hi,
You could use Python dictionaries as trees. Example:
to represent a simple tree:
'a' <- ( 'b' , 'c' )
'b' <- ( 'd', 'e', 'f')
'e' <- ( 'g')
'f' <- ('h', 'i', 'j')
treeD = { 'a' : (
{ 'b' : (
'd',
vivek khurana wrote:
> Hi! all
>
> i am a new member on this list. I have to implement
> tree data structure using python. How it can be done
> in python. Is there an existing data structure which
> can be used as tree?
Tuples can be used as trees: you can let them represent (data,
left_child, rig