I have the following code:
from collections import *
nested_dict = lambda: defaultdict(nested_dict)
data = nested_dict()
which enables me to write any new "path" in the dict as a one liner:
data['A']['B']['C']=3
which is what I want. But I want to get an exception when running (for any non existing path):
var = data['A']['XXX']['C']
I feel I need defaultdict when writing, plain dict when reading...
Or, is there a simple nice way to check if a 'path' exists in a defaultdict without modifying its contents...
I tried converting the defaultdict back to a dict before the lookup, hoping that:
dict(data)['A']['XXX']['C']
would raise a exception... but it kept creating missing keys...