def unflatten_dict(dictionary, sep='.'):
    """Unflatten a dictionary and convert into nested dictionaries
    
    https://stackoverflow.com/questions/6037503/python-unflatten-dict
    
    Parameters
    -----------
    d : dict
        Dictionary 
    
    Returns
    --------
    out : dict
        Unflattened dictionary including sub-dictionaries are unflattened.
    
    """
    
    resultDict = dict()
    for key, value in dictionary.items():
        parts = key.split(sep)
        d = resultDict
        for part in parts[:-1]:
            if part not in d:
                d[part] = dict()
            d = d[part]
        d[parts[-1]] = value
    return resultDict