Problem
Given a parsed JSON-like Python object data (built from nested dictionaries, lists, strings, numbers, booleans, and None) and a path array, write a function that safely returns the value at that path without raising an exception. Each path element is either a string key for dictionaries or an integer index for lists. If any step is invalid, return default instead.
Constraints
- 0 <= len(path) <= 10^4
- data may contain nested dictionaries, lists, primitive values, and None
- Path elements are only strings or integers
- The function must not raise KeyError, IndexError, or TypeError for invalid paths
Function Signature
def safe_get(data, path, default=None):
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.



