324 B
324 B
title, tags
| title | tags |
|---|---|
| all_equal | list,beginner |
Checks if all elements in a list are equal.
- Use
set()to eliminate duplicate elements and then uselen()to check if length is1.
def all_equal(lst):
return len(set(lst)) == 1
all_equal([1, 2, 3, 4, 5, 6]) # False
all_equal([1, 1, 1, 1]) # True