Mar-12-2020, 10:41 AM
from collections import defaultdict my_storage = defaultdict(dict) my_storage["foo"]["bar"] = 42 print(my_storage)
Output:defaultdict(<class 'dict'>, {'foo': {'bar': 42}})
Not existing keys are automatically created, if you assign accessing them.But this goes only one level deep.
This won't work:
my_storage["foo"]["bar"]["foo"] = 42
Error:KeyError: 'bar'
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!