Total Complexity | 3 |
Total Lines | 18 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | |||
3 | from benedict.dicts.keylist import keylist_util |
||
4 | from benedict.utils import type_util |
||
5 | |||
6 | |||
7 | def unflatten(d, separator='_'): |
||
8 | new_dict = d.copy() |
||
9 | new_dict.clear() |
||
10 | keys = list(d.keys()) |
||
11 | for key in keys: |
||
12 | value = d.get(key, None) |
||
13 | new_value = unflatten( |
||
14 | value, separator=separator) if type_util.is_dict(value) else value |
||
15 | new_keys = key.split(separator) |
||
16 | keylist_util.set_item(new_dict, new_keys, new_value) |
||
17 | return new_dict |
||
18 |