entry = self.companies
for path in options['path']: # options['path'] == ['up', 'middle', 'down']
entry = entry[path] # Need to get the object: self.companies['up']['middle']['down'] and change it
entry = options['value']
d = {1:{2:{3:{4:{5:0}}}}}
b = [1,2,3,4,5]
c = reduce(lambda d1, x: d1.get(x), b[:-1], d)
c
c[b[-1]] = 5
d
{1: {2: {3: {4: {5: 5}}}}}
entry = self.companies
entries = {}
for index, path in enumerate(options['path']): # options['path'] == ['up', 'middle', 'down']
if index == 0:
entries[index] = entry[path]
else:
entries[index] = entries[index - 1][path]
path_length = len(options['path'])
entries[path_length - 2][options['path'][path_length - 1]] = options['value']
Find more questions by tags Python