Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
21 lines (17 loc) · 419 Bytes

all-equal.md

File metadata and controls

21 lines (17 loc) · 419 Bytes
title type tags cover dateModified
Check if list elements are identical
snippet
list
fallen-leaves
2020-10-11 13:40:42 +0300

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