all_the_same   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2

1 Function

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