def _set_by_path(dic, keys, value, create_missing=True):
    """
    Set a nested object in dic by key sequence.

    Parameters
    ----------
    dic : dict
        The dictionary object.
    keys : list
        The key sequence.
    value : dict
        To be added.
    create_missing : bool
        Flag if set, to create if not present yet.

    Returns
    -------
        dict
            The resulting dictionary object.
    """
    d = dic
    i = 0
    n_key = len(keys) - 1
    while i < n_key:
        k = keys[i]
        if isinstance(k, int):
            assert isinstance(d, list), "Internal Error: %s is Expected as a list for %s." % (d, k)

            while len(d) <= k:
                d.insert(k, {})
            d = d[k]
        elif k in d:
            d = d[k]
        elif create_missing:
            next_key = keys[i + 1]
            if isinstance(next_key, int):
                if isinstance(d, list):
                    d.insert(k, [])
                else:
                    d[k] = []
            else:
                d[k] = {}
            d = d[k]
        else:
            return dic
        i += 1

    if isinstance(d, list) and keys[-1] >= len(d):
        d.insert(keys[-1], value)
    else:
        d[keys[-1]] = value
    return dic