In this python dictionary program, we will check all values are the same in a dictionary.
Steps to solve the program
- Take a dictionary as input.
- Use for loop to iterate over values of the dictionary using values().
- Use all() to check whether all values are the same in a dictionary.
- Print the output.
D1 = {'virat':50, 'rohit':50, 'rahul':50, 'hardik':50}
result = all(x == 50 for x in D1.values())
print(result)
Output :
True