bpod_core.misc.get_nested
- bpod_core.misc.get_nested(d, keys, default=None) Any
Retrieve a value from a nested dict using a Sequence of keys.
- Parameters:
d (
MutableMapping) – The dictionary from which to get a value.keys (
Sequence) – A sequence of keys representing the path to the desired value.default (
Any, optional) – The value to return if the path does not exist. Defaults to None.
- Returns:
The value at the nested path, or default if any key in the path is missing.
- Return type:
Any
Examples
>>> from bpod_core.misc import get_nested >>> dictionary = {'a': {'b': {'c': 42}}} >>> get_nested(dictionary, ['a', 'b', 'c']) 42
>>> get_nested(dictionary, ['a', 'x'], default='missing') 'missing'