in contrastthere are no limits on the types of objects that can be used as dictionary values we can use string key that maps to list valuefor exampleor we can have nested dictionary as value in another dictionary dictionary use cases dictionaries are extremely versatile and have numerous uses there are two major ways that dictionaries can be used the first is dictionaries where all the keys represent different instances of similar objectsfor exampleour stock dictionary this is an indexing system we use the stock symbol as an index to the values the values could even have been complicated self-defined objects that made buy and sell decisions or set stop-lossrather than our simple tuples the second design is dictionaries where each key represents some aspect of single structurein this casewe' probably use separate dictionary for each objectand they' all have similar (though often not identicalsets of keys this latter situation can often also be solved with named tuples these should typically be used when we know exactly what attributes the data must storeand we know that all pieces of the data must be supplied at once (when the item is constructedbut if we need to create or change dictionary keys over time or we don' know exactly what the keys might bea dictionary is more suitable using defaultdict we've seen how to use setdefault to set default value if key doesn' existbut this can get bit monotonous if we need to set default value every time we look up value for exampleif we're writing code that counts the number of times letter occurs in given sentencewe could do thisdef letter_frequency(sentence)frequencies {for letter in sentencefrequency frequencies setdefault(letter frequencies[letterfrequency return frequencies every time we access the dictionarywe need to check that it has value alreadyand if notset it to zero when something like this needs to be done every time an empty key is requestedwe can use different version of the dictionarycalled defaultdictfrom collections import defaultdict def letter_frequency(sentence)frequencies defaultdict(int