My code currently has to count things in a heavily nested dict into another. I have items that need to be indexed by 3 values and then counted. So, before my loop, I initialize a nested defaultdict like:
from collections import defaultdict
type_to_count_dic = defaultdict(
lambda: defaultdict(
lambda: defaultdict(int)
)
)
Which allows me to count the items within a tight loop like so:
for a in ...:
for b in ...:
for c in ...:
type_to_count_dic[a][b][c] += 1
Can anyone help me with a more idiomatic/Pythonic way of doing something like this?