def _set(obj, path, value):
    """
    set value for path in the given obj only if path exists.
    if not, IndexError or KeyError will be raised.
    params:
        obj - dict or list object
        path - list object represents keys in object
        value - value to be set
    """
    target = obj
    for elem in path[:-1]:
        if isinstance(target, list):
            target = target[int(elem)]
        elif isinstance(target, dict):
            if elem not in target:
                elem = int(elem)
            target = target[elem]
        else:
            raise TypeError('try to extract `%s` from target %s' % (elem,
                target))
    idx = path[-1]
    if isinstance(target, dict):
        target[idx] = value
    elif isinstance(target, list):
        target[int(idx)] = value
    else:
        raise TypeError('try to set `%s` for target %s' % (idx, target))
