either_24

Given a list of ints, return true if the list contains a 2 next to a 2 or a 4 next to a 4, but not both.

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, 2]

Output:

True

Test 2

Input:

[4, 4, 1]

Output:

True

Test 3

Input:

[4, 4, 1, 2, 2]

Output:

False

Test 4

Input:

[1, 2, 3, 4]

Output:

False

Test 5

Input:

[3, 5, 9]

Output:

False

Test 6

Input:

[1, 2, 3, 4, 4]

Output:

True

Test 7

Input:

[2, 2, 3, 4]

Output:

True

Test 8

Input:

[1, 2, 3, 2, 2, 4]

Output:

True

Test 9

Input:

[1, 2, 3, 2, 2, 4, 4]

Output:

False

Test 10

Input:

[1, 2]

Output:

False

Test 11

Input:

[2, 2]

Output:

True

Test 12

Input:

[4, 4]

Output:

True

Test 13

Input:

[2]

Output:

False

Test 14

Input:

[]

Output:

False