def is_leaf(self)return not (self right_child or self left_childdef has_any_children(self)return self right_child or self left_child def has_both_children(self)return self right_child and self left_child def replace_node_data(selfkeyvaluelcrc)self key key self payload value self left_child lc self right_child rc if self has_left_child()self left_child parent self if self has_right_child()self right_child parent self class binarysearchtreedef __init__(self)self root none self size def length(self)return self size def __len__(self)return self size def put(selfkeyval)if self rootself _put(keyvalself rootelseself root treenode(key,valself size self size def _put(selfkeyvalcurrent_node)if key current_node keyif current_node has_left_child()self _put(keyvalcurrent_node left_childelsecurrent_node left_child treenode(keyvalparent current_nodeelseif current_node has_right_child()self _put(keyvalcurrent_node right_childelsecurrent_node right_child treenode(keyvalparent current_node binary search trees