title: How to get the length of a tree in python binary search
body: <pre><code>class Node:
      def __init__(self,data=None):
          self.data=data
          self.left_child=None
          self.right_child=None
          self.parent=None
          self.root = None
      
  class BinarySearchTree:
      def __init__(self):
          self.root=None
      
      def add(self, data):
          if self.root == None:
              self.root = Node(data)
          else:
              self.add_helper(data, self.root)
  
      def add_helper(self, data, cur_node):
          if data &lt; cur_node.data:
              if cur_node.left_child == None:
                  cur_node.left_child = Node(data)
                  cur_node.left_child.parent = cur_node  # set parent
              else:
                  self.add_helper(data, cur_node.left_child)
          elif data &gt; cur_node.data:
  
              if cur_node.right_child == None:
                  cur_node.right_child = Node(data)
                  cur_node.right_child.parent = cur_node  # set parent
              else:
                  self.add_helper(data, cur_node.right_child)
  
          else:
              print(&quot;data already in tree!&quot;)
  
       def __len__(self):
          if self.root is None:
              return 0
          else:
              return (self.__len__(self.left_child) + 1 +self. __len__(self.right_child))
  </code></pre>
  <p>So i am trying to return the length of the binary search tree list, so i tried using the <strong>len</strong> method for my binary search tree class. However, this is not working correctly. I need it to be able to not take in any parameters, and just return an integer for the length of the binary search tree list. What am i missing and what am i doing wrong here?</p>