def nset(dic, keys, val):
    """ Set a nested key-value pair - in-place.
    No-op when a value already exists.
    Example:
        x = {}
        nset(x, ['a', 'b', 'c'], 0)
        print(x)
        > {'a': {'b': {'c': 0}}}

    """
    for key in keys[:-1]:
        dic = dic.setdefault(key, {})
    dic[keys[-1]] = dic.setdefault(keys[-1], val)
    return dic