elif key current_node keyreturn self _get(keycurrent_node left_childelsereturn self _get(keycurrent_node right_childdef __getitem__(selfkey)return self get(keyusing getwe can implement the in operation by writing __contains__ method for the binarysearchtree the __contains__ method will simply call get and return true if get returns valueor false if it returns none the code for __contains__ is shown below def __contains__(selfkey)if self _get(keyself root)return true elsereturn false recall that __contains__ overloads the in operator and allows us to write statements such asif 'northfieldin my_zip_treeprint("oom ya ya"finallywe turn our attention to the most challenging method in the binary search treethe deletion of key the first task is to find the node to delete by searching the tree if the tree has more than one node we search using the _get method to find the treenode that needs to be removed if the tree only has single nodethat means we are removing the root of the treebut we still must check to make sure the key of the root matches the key that is to be deleted in either case if the key is not found the del operator raises an error def delete(selfkey)if self size node_to_remove self _get(keyself rootif node_to_removeself remove(node_to_removeself size self size elseraise keyerror('errorkey not in tree'elif self size = and self root key =keyself root none self size self size elseraise keyerror('errorkey not in tree'def __delitem__(selfkey)self delete(keyonce we've found the node containing the key we want to deletethere are three cases that we must consider binary search trees