I want to add a value to a specific key within a nested dict, I have no idea how I could make that possible. So I have a:
thedict = {'one': {'two': {'three': {'four': None}}}}
and I want to add a value to four, or add another key/value pair to one:
thedict['one']['two']['three']['four'] = thevalue
thedict['one']['new'] = 'something else'
That is possible that way. But how can I make this more dynamic? For example, I have a list in this context:
thedict = {'one': {'two': {'three': {'four': None}}}}
thelist = ['one', 'two', 'three', 'four']
thevalue = 'something'
How can I then assign thevalue to four? Of course, thedict and thelist are dynamically created, I can't just do:
thedict[thelist[0]][thelist[1]][thelist[2]][thelist[3]] = thevalue