get_nested¶
- bpod_core.misc.get_nested(d, keys, default=None) ¶
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, default:None) – The value to return if the path does not exist.
- Returns:
The value at the nested path, or default if any key in the path is missing.
- Return type:
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'