Python · Intermediate · 35 min
Flatten nested source records
Convert nested dictionaries into safe dotted paths.
Task
Implement flatten_record(record) for a source API ingestion job. Dictionary leaves become dotted keys. Preserve lists and scalar values as they are. For example, {"customer": {"id": 7}} becomes {"customer.id": 7}.
Requirements
- Empty dictionaries contribute no leaf. Do not modify the input.
- Reject non-dictionary input with ValueError.
- Reject empty, non-string, or dotted dictionary keys at any depth with ValueError.
- Handle arbitrary dictionary nesting within Python’s normal recursion limit. Lists are leaves; do not inspect their contents.
Python dictionariesRecursionInput contracts
Loading exercise…