Newbie, need solution, modifying structures

Andrey Tatarinov elephantum at
Fri Jul 2 18:06:50 CEST 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
			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