def sort_by_index(index, array):
    """
    Sort the array with the given index and return a list of
    (<element>, <original index>, <new index>) tuples. Throw an assertion
    error (thrown by failed asserts automatically) if the arguments passed
    are invalid.

    >>> sort_by_index([ 0, 4, 2, 3, 1], \
["zero", "four", "two", "three", "one"])
    [('zero', 0, 0), ('one', 4, 1), ('two', 2, 2), ('three', 3, 3), \
('four', 1, 4)]

    >>> sort_by_index([ 0.0, 4.0, 2.0, 3.0, 1.0], \
["zero", "four", "two", "three", "one"])
    Traceback (most recent call last):
    ...
    AssertionError

    >>> sort_by_index([ 0, 4, 2, 3, 0], \
["zero", "four", "two", "three", "one"])
    Traceback (most recent call last):
    ...
    AssertionError

    >>> sort_by_index([ 0, 4, 2, 3], ["zero", "four", "two", "three", "one"])
    Traceback (most recent call last):
    ...
    AssertionError

    # My doctests #
    >>> sort_by_index([1, 4, 3, 2], ['one', 'four', 'three', 'two'])
    Traceback (most recent call last):
    ...
    AssertionError

    >>> sort_by_index([],[])
    []

    >>> sort_by_index([3, 2, 0, 1], ['three', 'two', 'zero', 'one'])
    [('one', 3, 0), ('zero', 2, 1), ('three', 0, 2), ('two', 1, 3)]
    """
    assert isinstance(index, list)
    assert isinstance(array, list)
    assert len(set(index)) == len(array)
    assert all([isinstance(idx, int) for idx in index])
    assert all([i in range(len(index)) for i in index])
    return [(array[index[i]], index[i], i) for i in range(0, len(index))]