Files
30-seconds-of-code/snippets/all_equal.md
Isabelle Viktoria Maciohsek 19f636408c Make expertise a field
2022-03-01 20:27:27 +02:00

438 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Check if list elements are identical list beginner 2019-08-20T11:39:18+03:00 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