object-oriented programming creating collection classes using inheritance collections ordereddict |the sorteddict class shown in this subsection attempts to mimic dict as closely as possible the major difference is that sorteddict' keys are always ordered based on specified key function or on the identity function sorteddict provides the same api as dict (except for having non-eval()-able repr())plus two extra methods that make sense only for an ordered collection (note that python introduced the collections ordereddict class--this class is different from sorteddict since it is insertion-ordered rather than key-ordered here are few examples of use to give flavor of how sorteddict worksd sorteddict sorteddict(dict( = = = )str lowerd[" " [" " del [" " [" " [" " str(dreturns"{' ' ' ' ' ' ' ' ' ' }the sorteddict implementation uses both aggregation and inheritance the sorted list of keys is aggregated as an instance variablewhereas the sorteddict class itself inherits the dict class we will start our code review by looking at the class line and the initializerand then we will look at all of the other methods in turn class sorteddict(dict)def __init__(selfdictionary=nonekey=none**kwargs)dictionary dictionary or {super(__init__(dictionaryif kwargssuper(update(kwargsself __keys sortedlist sortedlist(super(keys()keythe dict base class is specified in the class line the initializer tries to mimic the dict(functionbut adds second argument for the key function the super(__init__(call is used to initialize the sorteddict using the base class dict __init__(method similarlyif keyword arguments have been usedwe use the base class dict update(method to add them to the dictionary (note that only one occurrence of any keyword argument is acceptedso none of the keys in the kwargs keyword arguments can be "dictionaryor "keythe sorteddict class presented here is different from the one in rapid gui programming with python and qt by this authorisbn and from the one in the python package index