bpod_core.misc.set_nested

bpod_core.misc.set_nested(d, keys, value) None

Set a value in a nested dict, creating intermediate dicts as needed.

Parameters:
  • d (MutableMapping) – The dictionary in which to set the value.

  • keys (Sequence) – A sequence of keys representing the nested path where the value should be set.

  • value (Any) – The value to set at the specified path.

Return type:

None

Examples

>>> from bpod_core.misc import set_nested
>>> dictionary = {}
>>> set_nested(dictionary, ['a', 'b', 'c'], 42)
>>> dictionary
{'a': {'b': {'c': 42}}}
>>> set_nested(dictionary, ['a', 'b', 'x'], 99)
>>> dictionary
{'a': {'b': {'c': 42, 'x': 99}}}