Answers for "check if more than one element in list python"

5

python how to check if all elements in list are the same

List = ['Mon','Mon','Mon','Mon']
// Result from count matches with result from len()
result = List.count(List[0]) == len(List)
if (result):
   print("All the elements are Equal")
else:
   print("Elements are not equal")
Posted by: Guest on August-05-2020
1

python check if any elements in a list are different

# Basic syntax:
if your_list.count(your_list[0]) == len(your_list) # or:
if len(set(your_list)) == 1
       
# Example usage 1:
your_list = [1,1,1,1,1,1]
if your_list.count(your_list[0]) == len(your_list):
    print("All elements are identical")
else:
    print("Not all elements are identical")
--> All elements are identical
       
# Example usage 2:
your_list = [1,1,1,2,1,1]
if len(set(your_list)) == 1:
    print("All elements are identical")
else:
    print("Not all elements are identical")
--> Not all elements are identical
Posted by: Guest on January-17-2022

Code answers related to "check if more than one element in list python"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language