Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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
 
PREVIOUS NEXT
Tagged: #python #check #elements #list
ADD COMMENT
Topic
Name
7+3 =