Your question is Flatten Nested Portfolio JSON. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Goldman Sachs Asset & Wealth Management systems may represent complex portfolio holdings as nested JSON containing account metadata, security details, and arrays of positions. Write a function that flattens this structure into a dictionary whose keys are dot-delimited paths to leaf values.
Implement flatten_holdings(holdings), where holdings is a JSON-compatible Python dictionary. Traverse nested dictionaries and lists recursively:
None, become output values.. characters, so dots can safely separate path components.Return a dictionary mapping each leaf path string to its original value. The root input is always a dictionary. An empty root dictionary returns an empty result.
def flatten_holdings(holdings):