12
May
Python Multi-dimensional dicts using defaultdict
I asked previously how to avoid code like this: # Implement d[3][4] = 5 if not 3 in d: d[3] = {} d[3][4] = 5 I found the answer, and it lies in collections.defaultdict. defaultdict is just like dict, except that you pre-specify an initial default values for items that aren’t present. For example: d [...]
Continue Reading →