#60MediumDictionaries & Sets· Nested Dictionaries
Dictionary Deep Merge
Input format
`base`, `override`: dictionaries with string keys; values are numbers, strings, booleans, lists, null or nested dictionaries.
Output format
The merged dictionary.
Examples
Input: base = {"theme":"light","editor":{"font":14,"tabs":4}}, override = {"editor":{"font":16}}
Output: {"theme":"light","editor":{"font":16,"tabs":4}}
`editor` is a dictionary on both sides, so only `font` changes and `tabs` survives.
Input: base = {"plugins":["git","lint"],"debug":false}, override = {"plugins":["format"],"port":8080}
Output: {"plugins":["format"],"debug":false,"port":8080}
Lists are replaced, and `port` is a new key added at the end.
Constraints
- Nesting depth <= 10
- Total number of keys <= 1000
Study first
- #python
- #dictionaries
- #recursion
- #configuration
