I am using a nested defaultdict to keep code clean and reduce the redundant code.
I am constructing a dictionary such as:
{"Store1": {"Product1": 1}, "Store2": {"Product1": 2, "Product2": 1}}
I tried to implement the answer to this question Nested dictionary with defaults, which would raise the exception:
AttributeError: 'int' object has no attribute 'items'
from collections import defaultdict, Counter
d = defaultdict(lambda: defaultdict(lambda: Counter()))
d["Store1"]["Product1"] += 1
print(d)
is there anyway I can for example:
d["Store1"]["Product1"] += 1