A
Andrey Tatarinov
Hi all
I want to create tree structure and make some operations on it
class Node:
# nodes - list of childs
def height(self):
if len(nodes) != 0:
return max( [i.height() for i in nodes] ) + 1
else:
return 1
class NodeA(Node):
# specialized node
class NodeB(Node):
# another specialized node
now I want to substitute randomly selected subtree to another
def select_random(t):
# ... here are some recursive calls
return random.choice(t.nodes)
what is the easiest way to get thing with following semantics work :?
select_random(t) = generate_random()
I want to create tree structure and make some operations on it
class Node:
# nodes - list of childs
def height(self):
if len(nodes) != 0:
return max( [i.height() for i in nodes] ) + 1
else:
return 1
class NodeA(Node):
# specialized node
class NodeB(Node):
# another specialized node
now I want to substitute randomly selected subtree to another
def select_random(t):
# ... here are some recursive calls
return random.choice(t.nodes)
what is the easiest way to get thing with following semantics work :?
select_random(t) = generate_random()