title: Trying to implement a rebalance method in binary search tree, having issues getting the middle of a lyst inside of a method
body: <pre><code>    def inorder(self):
          &quot;&quot;&quot; inorder &quot;&quot;&quot;
          return self.inorder_helper(self.root)
  
      def inorder_helper(self, cur_node):
          &quot;&quot;&quot; inorder helper &quot;&quot;&quot;
          RecursionCounter()
          lyst = []
          if cur_node is not None:
              lyst += self.inorder_helper(cur_node.left_child)
              lyst.append(str(cur_node.data))
              lyst += self.inorder_helper(cur_node.right_child)
  
          final_lyst = list(map(int, lyst))
          return final_lyst
  
      def rebalance_tree(self):
          newlyst = inorder(self)
          newroot = len(newlyst-1) / 2
          midderoot = newlyst[newroot]
          print(newroot)
  
  bst = BinarySearchTree()
  
  bst.add(5)
  bst.add(10)
  bst.add(12)
  bst.add(20)
  bst.rebalance_tree()
  </code></pre>
  <p>So i have this binary search tree, and i am trying to add a method to make it a AVL tree, and have a rebalance tree method.</p>
  <p>So the first thing i need to do is take the middle value of the inorder lyst and make it into the root for the rebalance tree.</p>
  <p>However, this is not working correctly. If you take a look at the code, i tried to get a newlyst and make it equal to the method inorder, which returns a list of inorder.</p>
  <p>I then tried to take the length and divide it by 2, essentially getting the middle value, and then printing it.</p>
  <p>However i am getting a &quot;inorder&quot; is not defined error. how do i get the lyst from inorder inside of rebalance_tree? I need the rebalance tree to also have no parameters, but i could have helper functions.</p>