def _nest(dictionary, sep='.'):
    """Convert to a nested dict.
    :param dictionary: The dictionary to nest.
    :param sep: The separator to use to split the keys.
    :return: A dict of dicts with keys based on the (split at sep) input dict keys.

    Notes
    -----
    Build a dict of dicts from a flat dict, using `sep` to split string-based keys.

    Examples
    --------
    >>> _nest({1: 42, 'foo': 12})
    {1: 42, 'foo': 12}
    >>> _nest({1: 42, 'foo': 12, 'bar.qux': True})
    {1: 42, 'foo': 12, 'bar': {'qux': True}}
    >>> _nest({'1.2.3': 4})
    {1: {2: {3: 4}}}
    >>> _nest({'1.2.3': 4, '1.5': 6})
    {1: {2: {3: 4}, 5: 6}}
    """
    d2 = {}
    for k, v in dictionary.items():
        parents = k.split(sep)[:-1]
        d2sub = d2
        for parent in parents:
            if parent not in d2sub:
                d2sub[parent] = {}
            d2sub = d2sub[parent]
        k = k[k.rfind(sep) + 1:]
        d2sub[k] = v
    return d2
