Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_nested_value(data_dict, key_list):
- """Retrieving values in a nested iterable with a key list"""
- return reduce(lambda dictionary, key: dictionary[key], key_list, data_dict)
- def set_nested_value(data_dict, key_list, value):
- """Setting values in a nested iterable with a key list"""
- get_nested_value(data_dict, key_list[:-1])[key_list[-1]] = value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement