For example:
I need to create a dict of dict when iter over a list of keys
example I have this list
my_dict = {'root': {}}
my_keys = ['foo', 'bar', 'lorem', 'ipsum']
I wanna create a function to return this following dict
my_dict = {
'root': {
'foo': {
'bar': {
'lorem': {
'ipsum': {}
}
}
}
}
}
I think something using recursion, but I’m stucked in the logic.
>Solution :
cur_level = my_dict["root"]
for key in my_keys:
cur_level[key] = {}
cur_level = cur_level[key]