def set(list, index, item):
    """
    Return a list with the item at the specified index replaced with the
    given item.  If the index is out of bounds, return the list unmodified.
    """
    if list == () or index < 0:
        return list
    else:
        head, tail = list
        if index == 0:
            return (item, tail)
        else:
            return (head, set(tail, index - 1, item))