the sortedlist clear(method discards the existing list and replaces it with new empty list the sortedlist pop(method removes and returns the item at the given index positionor raises an indexerror exception if the index is out of range for the pop()__len__()and __str__(methodswe simply pass on the work to the aggregated self __list object we do not reimplement the __repr__(special methodso the base class object __repr__(will be called when the user writes repr(land is sortedlist this will produce string such as '<sortedlist sortedlist object at cec>'although the hexadecimal id will varyof course we cannot provide sensible __repr__(implementation because we would need to give the key function and we cannot represent function object reference as an eval()-able string we have not implemented the insert()reverse()or sort(method because none of them is appropriate if any of them are called an attributeerror exception will be raised if we copy sorted list using the [:idiom we will get plain list objectrather than sortedlist the easiest way to get copy is to import the copy module and use the copy copy(function--this is smart enough to copy sorted list (and instances of most other custom classeswithout any help howeverwe have decided to provide an explicit copy(methoddef copy(self)return sortedlist(selfself __keyby passing self as the first argument we ensure that self __list is simply shallow-copied rather than being copied and re-sorted (this is thanks to the __init__(method' type-testing elif clause the theoretical performance advantage of copying this way is not available to the copy copy(functionbut we can easily make it available by adding this line__copy__ copy when copy copy(is called it tries to use the object' __copy__(special methodfalling back to its own code if one isn' provided with this line in place copy copy(will now use the sortedlist copy(method for sorted lists (it is also possible to provide __deepcopy__(special methodbut this is slightly more involved--the copy module' online documentation has the details we have now completed the implementation of the sortedlist class in the next subsection we will make use of sortedlist to provide sorted list of keys for the sorteddict class