get_nested_value

get_nested_value#

eoio.utils.dict_tools.get_nested_value(input_dict: dict, keys: list)[source]#

Return a single value in a nested dictionary at the path loosely defined by the keys.

Note Useful if there are multiple values return by ‘get_value’ as you can filter the nested dictionaries that being searched

Example dictionary to search through and appropriate keys example_dict =

{“Satellite_1”: {“Bands”: {“B01”: {“Wavelength”: 10}, “B02”: { “Wavelength”: 20}}}, “Satellite_2”: {“Bands”: {“B01”: {“Wavelength”: 30}, “B02”: { “Wavelength”: 40}}}}

example_keys =

[“Satellite_2”, “B01”, “Wavelength”]

get_nested_value(example_dict, example_keys) == 30

Parameters:
  • input_dict – input dictionary through which to search

  • keys – list of keys ordered from out to in