def tuple_set(base, values, indices):
    """
    Creates a new tuple with the given values put at indices and otherwise the same as base. The
    list of indices must be in sorted order.
    """
    new = base[:indices[0]]
    for i in range(len(indices)-1):
        new += (values[i],) + base[indices[i]+1:indices[i+1]]
    return new + (values[-1],) + base[indices[-1]+1:]