Basic nesting
Input
flatten_dict({'a': {'b': 1, 'c': 2}, 'd': 3})
Output
{'a.b': 1, 'a.c': 2, 'd': 3}
The nested keys under 'a' are joined to form 'a.b' and 'a.c'. The top-level 'd' remains unchanged.
Full lesson preview
Convert a nested dictionary into a single-level dictionary using dot-separated keys for nested paths.
Problem statement
Task
Examples
Input
flatten_dict({'a': {'b': 1, 'c': 2}, 'd': 3})
Output
{'a.b': 1, 'a.c': 2, 'd': 3}
The nested keys under 'a' are joined to form 'a.b' and 'a.c'. The top-level 'd' remains unchanged.
Input format
Output format
Constraints
Samples
Input
flatten_dict({'x': {'y': {'z': 0}}, 'w': {}})
Output
{'x.y.z': 0}
'w' maps to an empty dict so it produces no output; 'x.y.z' holds the leaf value 0.