def swap(list, i, j):
    """
    Swaps elements at indices i and j in list. Indices must be within bounds of array. Index swapped with itself
    leaves the list unchanged.

    @param list: list of elements
    @type list: list
    @param i: index of element to be swapped with element at index j. Must be within bounds of array.
    @param j: index of element to be swapped with element at index i. Must be within bounds of array.
    @return: list with elements at indices i and j swapped. If i and j are equal, list is unchanged.
    @rtype: list
    """
    list[i], list[j] = list[j], list[i]
    return list
