def __setitem__(selfkv)self put(kvdef get(selfkey)if self rootres self _get(keyself rootif resreturn res payload elsereturn none elsereturn none def _get(selfkeycurrent_node)if not current_nodereturn none elif current_node key =keyreturn current_node elif key current_node keyreturn self _get(keycurrent_node left_childelsereturn self _get(keycurrent_node right_childdef __getitem__(selfkey)return self get(keydef __contains__(selfkey)if self _get(keyself root)return true elsereturn false 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(keydef splice_out(self) trees and tree algorithms