Python pattern: Using defaultdicts to initialise dictionaries

from blog James' Coffee Blog, | ↗ original
When you are working with dictionaries in Python, you may be familiar with the following process: You initialize a dictionary. You iterate over data. You check if a key is in a dictionary. If it isn’t, you add a default value. You add to the value associated with the key (i.e. to increment a counter, or add an item to a list or set). With the...