Merge with nested dicts
Input
deep_merge({'x': 1, 'y': {'a': 10}}, {'y': {'b': 20}, 'z': 3})
Output
{'x': 1, 'y': {'a': 10, 'b': 20}, 'z': 3}
y is merged recursively; x and z are preserved/added.
Full lesson preview
Merge two dictionaries recursively, combining nested mappings instead of overwriting them.
Problem statement
Task
Examples
Input
deep_merge({'x': 1, 'y': {'a': 10}}, {'y': {'b': 20}, 'z': 3})
Output
{'x': 1, 'y': {'a': 10, 'b': 20}, 'z': 3}
y is merged recursively; x and z are preserved/added.
Input format
Output format
Constraints
Samples
Input
deep_merge({'a': {'b': 1}}, {'a': {'c': 2}})
Output
{'a': {'b': 1, 'c': 2}}
Nested keys under 'a' are merged.