Passed
Push — master ( db2481...3bd527 )
by Fabio
03:28
created

benedict.core.unflatten.unflatten()   A

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 11
rs 9.85
c 0
b 0
f 0
cc 3
nop 2
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