def replace_at_idx(tup, i, val):
    """Replaces a value at index *i* of a tuple *tup* with value *val*

    :param tup: tuple to be updated
    :param i: index at which the value should be replaced
    :type i: integer
    :param val: new value at index i
    :type val: value
    :return: new tuple with replaced value
    """
    tup_list = list(tup)
    tup_list[i] = val

    return tuple(tup_list)