def getitem (selfk)"""return value associated with key (raise keyerror if not found""if self is empty)raise keyerrorkey errorrepr( )elsep self subtree search(self root)khook for balanced tree subclasses self rebalance access(pif ! key)raise keyerrorkey errorrepr( )return valuedef setitem (selfkv)"""assign value to key koverwriting existing value if present ""if self is empty)from linkedbinarytree leaf self add root(self item( , )elsep self subtree search(self root)kif key=kreplace existing item' value elementvalue hook for balanced tree subclasses self rebalance access(preturn elseitem self item( ,vif keykleaf self add right(piteminherited from linkedbinarytree elseleaf self add left(piteminherited from linkedbinarytree hook for balanced tree subclasses self rebalance insert(leafdef iter (self)"""generate an iteration of all keys in the map in order "" self firstwhile is not noneyield keyp self after(pcode fragment map operations for accessing and inserting items in the treemap class reverse iteration can be implemented with reverse using symmetric approach to iter