Is there a way to make a nested dictionary such that I can say mydict[x][y][z] += 1
, where mydict[x][y][z]
did not previously exist, and defaults to 0 (and would be 1 after incrementing)?
I looked into answers to a similar question in which you can say mydict[x][y][z] = 1
using defaultdict
from the collections
class (Declaring a multi dimensional dictionary in python), but this does not allow you to assume a default value and then increment.