Conditions | 3 |
Total Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | """Some helper functions.""" |
||
18 | def recursive_get(dict_, key): |
||
19 | """Get nested dictionary keys. |
||
20 | |||
21 | >>> recursive_get({"a": {"b": {"c": "d"}}}, "a.b.c") |
||
22 | "d" |
||
23 | |||
24 | Returns None if there are type conflicts. |
||
25 | """ |
||
26 | keys = key.split('.') |
||
27 | last = keys.pop(-1) |
||
28 | |||
29 | dict_ = dict_.copy() |
||
30 | for key in keys: |
||
31 | value = dict_.get(key) |
||
32 | if not isinstance(value, dict): |
||
33 | return |
||
34 | dict_ = value |
||
35 | return dict_.get(last) |
||
36 |