the ordereddict is often used in conjunction with the sorted method to create sorted dictionary for examplein the following example we use lambda function to sort on the valueshere we use numerical expression to sort the integer valuesdefaultdict the defaultdict object is subclass of dict and therefore they share methods and operations it acts as convenient way to initialize dictionaries with dictpython will throw keyerror when attempting to access key that is not already in the dictionary the defaultdict overrides one method__missing__(key)and creates new instance variabledefault_factory with defaultdictrather than throw an errorit will run the functionsupplied as the default_factory argumentwhich will generate value simple use of defaultdict is to set default_factory to int and use it to quickly tally the counts of items in the dictionaryfor example