Python Practice › Dictionary Programs › Program 56
Are all values the same?
Write a Python program to check whether all values in a dictionary are the same.
Input
{"virat": 50, "rohit": 50, "rahul": 50, "hardik": 50}Output
True
Approach
- A set of the values has one item when they are all equal.
Solution
d = {"virat": 50, "rohit": 50, "rahul": 50, "hardik": 50}print(len(set(d.values())) == 1)Output
True
Learn the concept
New to this topic? Read the lesson, then come back.