def inflate_dict(dct, sep=".", deep=-1):
    """Inflates a flattened dict.

    Will look in simple dict of string key with string values to
    create a dict containing sub dicts as values.

    Samples are better than explanation:

        >>> from pprint import pprint as pp
        >>> pp(inflate_dict({'a.x': 3, 'a.y': 2}))
        {'a': {'x': 3, 'y': 2}}

    The keyword argument ``sep`` allows to change the separator used
    to get subpart of keys:

        >>> pp(inflate_dict({'etc/group': 'geek', 'etc/user': 'bob'}, "/"))
        {'etc': {'group': 'geek', 'user': 'bob'}}

    Warning: you cannot associate a value to a section:

        >>> inflate_dict({'section.key': 3, 'section': 'bad'})
        Traceback (most recent call last):
        ...
        TypeError: 'str' object does not support item assignment

    Of course, dict containing only keys that doesn't use separator will be
    returned without changes:

        >>> inflate_dict({})
        {}
        >>> inflate_dict({'a': 1})
        {'a': 1}

    Argument ``deep``, is the level of deepness allowed to inflate dict:

        >>> pp(inflate_dict({'a.b.c': 3, 'a.d': 4}, deep=1))
        {'a': {'b.c': 3, 'd': 4}}

    Of course, a deepness of 0 won't do anychanges, whereas deepness of -1 is
    the default value and means infinite deepness:

        >>> pp(inflate_dict({'a.b.c': 3, 'a.d': 4}, deep=0))
        {'a.b.c': 3, 'a.d': 4}

    """

    def mset(dct, k, v, sep=".", deep=-1):
        if deep == 0 or sep not in k:
            dct[k] = v
        else:
            khead, ktail = k.split(sep, 1)
            if khead not in dct:
                dct[khead] = {}
            mset(dct[khead], ktail, v,
                 sep=sep,
                 deep=-1 if deep < 0 else deep - 1)

    res = {}
    ## sorting keys ensures that colliding values if any will be string
    ## first set first so mset will crash with a TypeError Exception.
    for k in sorted(dct.keys()):
        mset(res, k, dct[k], sep, deep)
    return res