Files
30-seconds-of-code/python/snippets/all-equal.md
2023-05-01 22:43:50 +03:00

419 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Check if list elements are identical snippet
list
fallen-leaves 2020-10-11T13:40:42+03:00

Checks if all elements in a list are equal.

  • Use set() to eliminate duplicate elements and then use len() to check if length is 1.
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