Newbie, need solution, modifying structures

Andrey Tatarinov elephantum at dezcom.mephi.ru
Fri Jul 2 12:06:50 EDT 2004


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()



More information about the Python-list mailing list