#K9131. Add to Nested Dictionary
Add to Nested Dictionary
Add to Nested Dictionary
You are given a nested dictionary and a list of keys representing a nested path. Your task is to insert a given value at the location specified by the keys. If any key along the path does not exist, create a new dictionary at that key.
Formally, you are given a dictionary d, a list of keys [k_1, k_2, \dots, k_n] (keys are given in order) and a value v. Your goal is to update the dictionary so that the nested element \[ d[k_1][k_2]\dots[k_n] = v \] is set to v.
Print the updated dictionary in JSON format.
inputFormat
The input is given through stdin as three separate lines:
- A JSON object representing the initial dictionary.
- A JSON array of strings representing the keys that define the nested path.
- A JSON value (number, string, etc.) that is to be inserted into the dictionary.
outputFormat
Print the updated dictionary as a JSON object to stdout.
## sample{"level1": {"level2": {"level3": "value"}}}
["level1", "level2", "level4"]
"new_value"
{"level1":{"level2":{"level3":"value","level4":"new_value"}}}