Learn Tree Traversal by Building a Binary Search Tree - Step 35

I’m not sure what I am missing, but I am having trouble returning the node.right to replace the left child at the end of the code…

def _insert(self, node, key):
    if node is None:
        return TreeNode(key)
    if key < node.key:
        node.left = self._insert(node.left, key)
    elif key > node.key:
        node.right = self._insert(node.right, key)
    return node

def search(self, key):
    return self._search(self.root, key)

def _search(self, node, key):
    if node is None or node.key == key:
        return node
    if key < node.key:
        return self._search(node.left, key)
    return self._search(node.right, key)

def delete(self, key):
    self.root = self._delete(self.root, key)

def _delete(self, node, key):
    if node is None:
        return node
    if key < node.key:
        node.left = self._delete(node.left, key)
    elif key > node.key:
        node.right = self._delete(node.right, key)

User Editable Region

    else:
        if node.left == None:
            return node.right

User Editable Region

User Editable Region

    else:
        if node.left == None:
            return node.right

User Editable Region


### Your browser information:

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36</code>

### Challenge Information:
Learn Tree Traversal by Building a Binary Search Tree - Step 35
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-tree-traversal-by-building-a-binary-search-tree/step-35

You cannot use == to compare with None. You should use the is operator.

1 Like

Oh my gosh. I was so focused on my return line :sweat_smile:
Thank you…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.