Are all values the same?

EasyDictionary Programs · 56 of 94

Write a Python program to check whether all values in a dictionary are the same.

Advertisement
Input
{"virat": 50, "rohit": 50, "rahul": 50, "hardik": 50}
Output
True

Approach

  1. A set of the values has one item when they are all equal.

Solution

Python
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.

More dictionary programs

← All 94 Dictionary Programs

Leave a Comment