def unflatten(dictionary):
    """ Unflattens a dictionary by splitting keys at '.'s.

    This function unflattens a hierarchical dictionary by splitting
    its keys at '.'s. It is used internally for converting the
    configuration dictionary to more convenient formats. Implementation was
    inspired by `this StackOverflow post
    <https://stackoverflow.com/questions/6037503/python-unflatten-dict>`_.

    Parameters
    ----------
    dictionary : dict
        The flat dictionary to be unflattened.

    Returns
    -------
    dict
        The unflattened dictionary.

    See Also
    --------
    lfads_tf2.utils.flatten : Performs the opposite of this operation.

    """

    resultDict = dict()
    for key, value in dictionary.items():
        parts = key.split(".")
        d = resultDict
        for part in parts[:-1]:
            if part not in d:
                d[part] = dict()
            d = d[part]
        d[parts[-1]] = value
    return resultDict