return valuesview(selfdef items(self)return itemsview(selfdef __iter__(self)'''for in self syntax''return self ordered_keys __iter__(the __new__ method creates new dictionary and then puts an empty list on that object we don' override __init__as the default implementation works (actuallythis is only true if we initialize an empty dictsorted objectwhich is standard behavior if we want to support other variations of the dict constructorwhich accept dictionaries or lists of tupleswe' need to fix __init__ to also update our ordered_ keys listthe two methods for setting items are very similarthey both update the list of keysbut only if the item hasn' been added before we don' want duplicates in the listbut we can' use set hereit' unorderedthe keysitemsand values methods all return views onto the dictionary the collections library provides three read-only view objects onto the dictionarythey use the __iter__ method to loop over the keysand then use __getitem__ (which we didn' need to overrideto retrieve the values sowe only need to define our custom __iter__ method to make these three views work you would think the superclass would create these views properly using polymorphismbut if we don' override these three methodsthey don' return properly ordered views finallythe __iter__ method is the really special oneit ensures that if we loop over the dictionary' keys (using for in syntax)it will return the values in the correct order it does this by returning the __iter__ of the ordered_keys listwhich returns the same iterator object that would be used if we used for in on the list instead since ordered_keys is list of all available keys (due to the way we overrode other methods)this is the correct iterator object for the dictionary as well let' look at few of these methods in actioncompared to normal dictionaryds dictsorted( {ds[' ' ds[' ' ds setdefault(' ' [' ' [' ' setdefault(' '