V
vertigo
Hello
I have trees like this:
I use nltk package - but it should not matter here.
I could change it's lafes (add node) like this:
But my tree has many levels and it's imposibble to address it like:
tree6[0][1][0][1][1][1][0]..........
So i wanted to 'travel thru my tree' to last node which should be changed:
The problem is that subtree is some kind of a new variable (not pointer)
so changing it i will not alter tree6. How to alter tree6 while
'travelling along it's nodes',
without messy referencing as tree6[0][1][0][1][1][1][0].......... ?
Thanx
I have trees like this:
('main': 'sub1' 'sub2')from nltk_lite.parse.tree import Tree
tree6 = Tree('main', ['sub1', 'sub2'])
tree6
I use nltk package - but it should not matter here.
I could change it's lafes (add node) like this:
('main': ('newsub': ) 'sub2')tree6[0] = Tree('newsub',[])
tree6
But my tree has many levels and it's imposibble to address it like:
tree6[0][1][0][1][1][1][0]..........
So i wanted to 'travel thru my tree' to last node which should be changed:
('main': 'sub1' 'sub2')tree6 = Tree('main', ['sub1', 'sub2'])
subtree = tree6[0]
subtree 'sub1'
subtree = Tree('newsub',[])
subtree ('newsub': )
tree6
The problem is that subtree is some kind of a new variable (not pointer)
so changing it i will not alter tree6. How to alter tree6 while
'travelling along it's nodes',
without messy referencing as tree6[0][1][0][1][1][1][0].......... ?
Thanx