

def flat_to_nested(data, instance=None, attname=None, separator=None, loads=None):
    'Convert a flat representation of a dictionary to\na nested representation. Fields in the flat representation are separated\nby the *splitter* parameters.\n\n:parameter data: a flat dictionary of key value pairs.\n:parameter instance: optional instance of a model.\n:parameter attribute: optional attribute of a model.\n:parameter separator: optional separator. Default ``"__"``.\n:parameter loads: optional data unserializer.\n:rtype: a nested dictionary'
    separator = (separator or JSPLITTER)
    val = {
        
    }
    flat_vals = {
        
    }
    for (key, value) in iteritems(data):
        if (value is None):
            continue
        keys = key.split(separator)
        if attname:
            if (keys.pop(0) != attname):
                continue
        if loads:
            value = loads(value)
        if (not keys):
            if (value is None):
                val = flat_vals = {
                    
                }
                break
            else:
                continue
        else:
            flat_vals[key] = value
        d = val
        lk = keys[(- 1)]
        for k in data[:(- 1)]:
            if (k not in d):
                nd = {
                    
                }
                d[k] = nd
            else:
                nd = d[k]
                if (not isinstance(nd, dict)):
                    nd = {
                        '': nd,
                    }
                    d[k] = nd
            d = nd
        if (lk not in d):
            d[lk] = value
        else:
            d[lk][''] = value
    if (instance and flat_vals):
        for (attr, value) in iteritems(flat_vals):
            setattr(instance, attr, value)
    return val

dataset/ETHPy150Open lsbardel/python-stdnet/stdnet/utils/jsontools.py flat_to_nested/VarMisuse@187/364 `keys`->`data`