Created
February 22, 2019 15:49
-
-
Save BurhanH/77aae592a6bf565b17d09b01a72631b9 to your computer and use it in GitHub Desktop.
How to check if all elements in a list are equal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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