Test Setup Failed
Push — master ( 8037aa...ac2306 )
by Ken M.
01:37
created

all_the_same()   A

Complexity

Conditions 3

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
from typing import List, Any
2
3
4
def all_the_same(elements: List[Any]) -> bool:
5
    is_same = all([1 if elements[index + 1] == value else 0
6
                  for index, value in enumerate(elements[:-1])])
7
    return is_same
8
9
10
if __name__ == '__main__':
11
    print("Example:")
12
    print(all_the_same([1, 1, 1]))
13
14
    # These "asserts" are used for self-checking and not for an auto-testing
15
    assert all_the_same([1, 1, 1]) == True
16
    assert all_the_same([1, 2, 1]) == False
17
    assert all_the_same(['a', 'a', 'a']) == True
18
    assert all_the_same([]) == True
19
    assert all_the_same([1]) == True
20
    print("Coding complete? Click 'Check' to earn cool rewards!")
21