def insertValue(self, a):
        """ Inserts a new value to tree and keeps it balanced """
        if self.root is None:
            self.root = Node(a)
        elif a is not None:
            node = self.findNode(a)
            res = node.contains(a)
            if res:  return res
            # try to insert a new value into existing node
            node.insertValue(a)
            self.__fixNodeInsert(node)
        return self
 Inserts a new value to tree and keeps it balanced 
recipes/Python/577898_23_Tree/recipe-577898.py