w3resource
Python Exercises

Python: Check if all items of a list is equal to a given string

Python List: Exercise - 57 with Solution

Write a Python program to check if all items of a list is equal to a given string.

Python: Check if all items of a list is equal to a given string

Sample Solution:-

Python Code:

color1 = ["green", "orange", "black", "white"]
color2 = ["green", "green", "green", "green"]

print(all(c == 'blue' for c in color1))
print(all(c == 'green' for c in color2))

Sample Output:

False                                                                                                         
True

Flowchart:

Flowchart: Check if all items of a list is equal to a given string

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to convert a string to a list.
Next: Write a Python program to replace the last element in a list with another list.

What is the difficulty level of this exercise?