| Total Complexity | 4 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from benedict.core import clone |
||
| 2 | from benedict.dicts.keylist import keylist_util |
||
| 3 | from benedict.utils import type_util |
||
| 4 | |||
| 5 | |||
| 6 | def _unflatten_item(key, value, separator): |
||
| 7 | keys = key.split(separator) |
||
| 8 | if type_util.is_dict(value): |
||
| 9 | return (keys, unflatten(value, separator=separator)) |
||
| 10 | return (keys, value) |
||
| 11 | |||
| 12 | |||
| 13 | def unflatten(d, separator="_"): |
||
| 14 | new_dict = clone(d, empty=True) |
||
| 15 | keys = list(d.keys()) |
||
| 16 | for key in keys: |
||
| 17 | value = d.get(key, None) |
||
| 18 | new_keys, new_value = _unflatten_item(key, value, separator) |
||
| 19 | keylist_util.set_item(new_dict, new_keys, new_value) |
||
| 20 | return new_dict |
||
| 21 |