object-oriented programming the dict api includes the dict fromkeys(class method this method is used to create new dictionary based on an iterable each element in the iterable becomes keyand each key' value is either none or the specified value because this is class method the first argument is provided automatically by python and is the class for dict the class will be dictand for sorteddict it is sorteddict the return value is dictionary of the given class for exampleclass mydict(sorteddict sorteddict)pass mydict fromkeys("veins" str(dreturns"{' ' ' ' ' ' ' ' ' ' } __class__ __name__ returns'mydictso when inherited class methods are calledtheir cls variable is set to the correct classjust like when normal methods are called and their self variable is set to the current object this is different from and better than using static method because static method is tied to particular class and does not know whether it is being executed in the context of its original class or that of subclass def __setitem__(selfkeyvalue)if key not in selfself __keys add(keyreturn super(__setitem__(keyvaluethis method implements the [keyvalue syntax if the key isn' in the dictionary we add it to the list of keysrelying on the sortedlist to put it in the right place then we call the base class methodand return its result to the caller to support chainingfor examplex [keyvalue notice that in the if statement we check to see whether the key already exists in the sorteddict by using not in self because sorteddict inherits dicta sorteddict can be used wherever dict is expectedand in this case self is sorteddict when we reimplement dict methods in sorteddictif we need to call the base class implementation to get it to do some of the work for uswe must be careful to call the method using super()as we do in this method' last statementdoing so prevents the reimplementation of the method from calling itself and going into infinite recursion we do not reimplement the __getitem__(method since the base class version works fine and has no effect on the ordering of the keys def __delitem__(selfkey)tryself __keys remove(keyexcept valueerrorraise keyerror(keyreturn super(__delitem__(key