swap_ends

Given a list of ints, swap the first and last elements in the list. Return the modified list. The list length will be at least 1.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

[1, 2, 3, 4]

Output:

[4, 2, 3, 1]

Test 2

Input:

[1, 2, 3]

Output:

[3, 2, 1]

Test 3

Input:

[8, 6, 7, 9, 5]

Output:

[5, 6, 7, 9, 8]

Test 4

Input:

[3, 1, 4, 1, 5, 9]

Output:

[9, 1, 4, 1, 5, 3]

Test 5

Input:

[1, 2]

Output:

[2, 1]

Test 6

Input:

[1]

Output:

[1]