Deep-Merge Configuration Dicts

easy
Unit 4 · Dicts0/3 to milestone

Apps layer configuration: defaults, then an environment file, then command-line overrides. A shallow {**a, **b} replaces whole nested sections. You need a deep merge.

Implement deep_merge(base, override), returning a new dict:

  • Keys only in one input are copied over.
  • If both values are dicts, merge them recursively.
  • Otherwise the override's value wins, including lists, which are replaced rather than concatenated.
  • An override value of None deletes the key.
  • Neither input may be modified, and nested dicts in the result must not be the same objects as in the inputs.
#dicts#recursion#config2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Deep-Merge Configuration Dicts · TechGradify