Newbie, need solution, modifying structures

  • Thread starter Andrey Tatarinov
  • Start date
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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top