Skip to content

Instantly share code, notes, and snippets.

@BurhanH
Created February 22, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurhanH/77aae592a6bf565b17d09b01a72631b9 to your computer and use it in GitHub Desktop.
Save BurhanH/77aae592a6bf565b17d09b01a72631b9 to your computer and use it in GitHub Desktop.
How to check if all elements in a list are equal
lst = ['a', 'a', 'a']
print(len(set(lst)) == 1)
# True
print(all((x == lst[0]) for x in lst))
# True
print(lst.count(lst[0]) == len(lst))
# True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment