Problem · Hash Table

Dynamic Path Accessor

EasyNvidiaOA

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.

Function Description

Complete the function get_dict_value in the editor below.

get_dict_value has the following parameters:

  • obj: a Python dictionary
  • string 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

Examples
01 · Example 1
obj = [["car"], [":"], ["wheels", ":", "2", "gears", ":", "5"]]
path = "car.gears"
return = 5
The function call get_dict_value(obj, "car.gears") should return 5.
Constraints
1 ≤ n(number of strings) ≤ 500
More Nvidia problems
drafts saved locally
public String breakPalindrome(String[][] obj, String path) {
  // write your code here
}
obj[["car"], [":"], ["wheels", ":", "2", "gears", ":", "5"]]
path"car.gears"
expected5
sign in to submit