Dynamic Path Accessor
Hi! Just a heads-up ~ FastPrep currently doesn't support dictionaries as an input type, so submitting code with that will throw errors. But no worries! The problem statement is pretty clear about what’s expected 🍻
Implement a function called get_dict_value that takes two arguments: a dictionary called dict and a string called path. The path string represents the nested keys of the dictionary, separated by dots. The function should return the value at the specified path or None (the Python null value, not a string) if the path does not exist.
Complete the function get_dict_value in the editor below.
get_dict_value has the following parameters:
obj: a Python dictionarystring path: the path to the desired value if it exists
Returns
The value at the specified path, or None (the Python null value, not a string) if the path does not exist
1Example 1
get_dict_value(obj, "car.gears") should return 5.Constraints
Limits and guarantees your solution can rely on.
1 ≤ n(number of strings) ≤ 500