Merge Two Config Dicts

Easy ⏱ 8 min 75% acceptance ★★★★★ 4.5
Write a function merge_configs(base, override) that returns a new dict combining base and override, where keys present in both take the value from override. Neither input dict should be mutated. Use the | merge operator.

Examples

Example 1
Input
merge_configs({'debug': False, 'timeout': 30}, {'timeout': 60})
Output
{'debug': False, 'timeout': 60}
Explanation

override wins on the shared key timeout.

Constraints

  • Do not mutate base or override.
  • Use the `|` operator (Python 3.9+).

Topics

Dictionariesmerging

Companies

MicrosoftOracle

Hints

Hint 1

`base | override` produces a new merged dict, right-hand side wins on conflicts.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.