| Total Complexity | 2 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |