I want to do this:
foo23 = base["foo23"]["subfoo"]["subsubfoo"]
print(foo23)
[2,3]
foo23 = base["noexist"]["nothereeither"]["nope"]
print(foo23)
None
I can't seem to accomplish this, using defaultdict and specialized dictionaries. The failed access of the first call can return a 'None', but then the following fields cause an exception for it not being subscriptable. Just wondering if this is possible.
If you wanted to walk a tree by a list of keys where the tree might have nodes that where dictionaries or lists or values then you might do:
That will give you:
while failing fast and without resorting to a casting your tree to a default dict.
If you wanted to support a list of keys that was a dot separated sting you might be able to do that if you guarded for only passing integer indexes to lists. Perhaps something like: