make_middle

Given a list of ints of even length, return a new list length 2 containing the middle two elements from the original list. The original list will be length 2 or more.

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:

[2, 3]

Test 2

Input:

[7, 1, 2, 3, 4, 9]

Output:

[2, 3]

Test 3

Input:

[1, 2]

Output:

[1, 2]

Test 4

Input:

[5, 2, 4, 7]

Output:

[2, 4]

Test 5

Input:

[9, 0, 4, 3, 9, 1]

Output:

[4, 3]