if we had tried this with dd just regular dictionarywe would have gotten an error the first time the program reached dd[ ]+= because dd[cdid not yet exist but since we declared dd to be defaultdict(int)each value is automatically assigned value of upon creationand so we avoid the error note that we could use regular dictionary if we add an if statement into the loopand there is also function of regular dictionaries that allows you to set default valuebut defaultdict runs faster we can use types other than integers here is an example with stringss 'aababcabcdabcd dd defaultdict(strfor in sdd[ ]+'defaultdict({' ''*****'' ''***'' ''****'' ''**'}use list for listsset for setsdict for dictionariesand float for floats you can use various other classestoo the default value for integers is for lists is []for sets is set()for dictionaries is {and for floats is if you would like different default valueyou can use an anonymous function like belowdd defaultdict(lambda: used with the code from the first examplethis will producedefaultdict({' ' ' ' ' ' ' ' }