Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def get_nested_value(data_dict, key_list):
  2. """Retrieving values in a nested iterable with a key list"""
  3. return reduce(lambda dictionary, key: dictionary[key], key_list, data_dict)
  4.  
  5.  
  6. def set_nested_value(data_dict, key_list, value):
  7. """Setting values in a nested iterable with a key list"""
  8. get_nested_value(data_dict, key_list[:-1])[key_list[-1]] = value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement