inverted_d {vk for kv in items()the resultant dictionary can be inverted back to the original dictionary if all the original dictionary' values are unique--but the inversion will fail with typeerror being raised if any value is not hashable just like list and set comprehensionsthe iterable in dictionary comprehension can be another comprehensionso all kinds of nested comprehensions are possible default dictionaries |default dictionaries are dictionaries--they have all the operators and methods that dictionaries provide what makes default dictionaries different from plain dictionaries is the way they handle missing keysin all other respects they behave identically to dictionaries (in object-oriented termsdefaultdict is subclass of dictobject-oriented programmingincluding subclassingis covered in if we use nonexistent ("missing"key when accessing dictionarya keyerror is raised this is useful because we often want to know whether key that we expected to be present is absent but in some cases we want every key we use to be presenteven if it means that an item with the key is inserted into the dictionary at the time we first access it for exampleif we have dictionary which does not have an item with key mthe code [mwill raise keyerror exception but if is suitably created default dictionaryif an item with key is in the default dictionarythe corresponding value is returned the same as for dictionary--but if is not key in the default dictionarya new item with key is created with default valueand the newly created item' value is returned uniquewords py earlier we wrote small program that counted the unique words in the files it was given on the command line the dictionary of words was created like thiswords {each key in the words dictionary was word and each value an integer holding the number of times the word had occurred in all the files that were read here' how we incremented whenever suitable word was encounteredwords[wordwords get(word we had to use dict get(to account for when the word was encountered the first time (where we needed to create new item with count of and for when the word was encountered subsequently (where we needed to add to the word' existing count