object-oriented programming the base class methods dict get()dict __getitem__((for the [ksyntax)dict __len__((for len( ))and dict __contains__((for in dall work fine as they are and don' affect the key orderingso we have not needed to reimplement them the last dict method that we must reimplement is copy(def copy(self) sorteddict(super(sorteddictdupdate(selfd __keys self __keys copy(return the easiest reimplementation is simply def copy(self)return sorteddictselfwe've chosen slightly more complicated solution that avoids re-sorting the already sorted keys we create an empty sorted dictionarythen update it with the items in the original sorted dictionary using the base class dict update(to avoid the sorteddict update(reimplementationand replace the dictionary' self __keys sortedlist with shallow copy of the original one when super(is called with no arguments it works on the base class and the self object but we can make it work on any class and any object by passing in class and an object explicitly using this syntaxthe super(call works on the immediate base class of the class it is givenso in this case the code has the same effect as (and could be written asdict update(dselfin view of the fact that python' sort algorithm is very fastand is particularly well optimized for partially sorted liststhe efficiency gain is likely to be little or nothing except for huge dictionaries howeverthe implementation shows that at least in principlea custom copy(method can be more efficient than using the copy_of_x classofx(xidiom that python' built-in types support and just as we did for sortedlistwe have set __copy__ copy so that the copy copy(function uses our custom copy method rather than its own code def value_at(selfindex)return self[self __keys[index]def set_value_at(selfindexvalue)self[self __keys[index]value these two methods represent an extension to the dict api sinceunlike plain dicta sorteddict is orderedit follows that the concept of key index positions is applicable for examplethe first item in the dictionary is at index position and the last at position len( both of these methods operate on the dictionary item whose key is at the index-th position in the sorted keys list thanks to inheritancewe can look up values in the sorteddict using the item access op