python check if all elements in list are equal code example
Example 1: python how to check if all elements in list are the same
List = ['Mon','Mon','Mon','Mon']
result = List.count(List[0]) == len(List)
if (result):
print("All the elements are Equal")
else:
print("Elements are not equal")
Example 2: how to check if all values in list are equal python
res = all(ele == lst[0] for ele in lst)
if(res):
print("Equal")
Example 3: how to check if all values in list are equal python
if len(lst) < 0 :
res = True
res = lst.count(lst[0]) == len(lst)
if(res):
print("Equal")
Example 4: python check if 3 values are equal
cat, dog, rabbit = 1, 1, 1
print (cat == dog == rabbit)
>>> True
cat, dog, donkey = 1, 1, 2
print (cat == dog == donkey)
>>> False