collection data types when default dictionary is createdwe can pass in factory function factory function is function thatwhen calledreturns an object of particular type all of python' built-in data types can be used as factory functionsfor exampledata type str can be called as str()--and with no argument it returns an empty string object the factory function passed to default dictionary is used to create default values for missing keys note that the name of function is an object reference to the function--so when we want to pass functions as parameterswe just pass the name when we use function with parenthesesthe parentheses tell python that the function should be called the program uniquewords py has one more line than the original uniquewords py program (import collections)and the lines for creating and updating the dictionary are written differently here is how the default dictionary is createdwords collections defaultdict(intthe words default dictionary will never raise keyerror if we were to write words["xyz"and there was no item with key "xyz"when the access is attempted and the key isn' foundthe default dictionary will immediately create new item with key "xyzand value (by calling int())and this value is what will be assigned to words[word+ now we no longer need to use dict get()instead we can simply increment the item' value the very first time word is encountereda new item is created with value (to which is immediately added)and on every subsequent access is added to whatever the current value happens to be we have now completed our review of all of python' built-in collection data typesand couple of the standard library' collection data types in the next section we will look at some issues that are common to all of the collection data types ordered dictionaries |the ordered dictionaries type--collections ordereddict--was introduced with python in fulfillment of pep ordered dictionaries can be used as drop-in replacements for unordered dicts because they provide the same api the difference between the two is that ordered dictionaries store their items in the order in which they were inserted-- feature that can be very convenient note that if an ordered dictionary is passed an unordered dict or keyword arguments when it is createdthe item order will be arbitrarythis is because under the hood python passes keyword arguments using standard unordered