79560691

Date: 2025-04-07 20:04:32
Score: 0.5
Natty:
Report link

Consider using memory_graph to visualize your data so you have a better understanding of it.

import memory_graph as mg # see link above for install instructions

class Tree(object):

    def __init__(self):
        self.left = None
        self.data = 0
        self.right = None
        
    def insert(self,num):
        self.data = self.data + 1
        if num == 0:
            if self.left == None:
                self.left = Tree()
            return self.left
        elif num == 1:
            if self.right == None:
                self.right = Tree()
            return self.right

data = [[0,1,0,0,1],[0,0,1],[0,0],[0,1,1,1,0]]

root = Tree()
for route in data:
    build_tree = root
    for i in range (0,len(route)):
        num = route[i]
        build_tree = build_tree.insert(num)

mg.show(locals()) # graph all local variables

tree

Full disclosure: I am the developer of memory_graph.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: bterwijn