Check all values are the same in a dictionary.

In this python dictionary program, we will check all values are the same in a dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Use for loop to iterate over values of the dictionary using values().
  3. Use all() to check whether all values are the same in a dictionary.
  4. 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
				
			

convert a matrix into a dictionary.

create a dictionary grouping a sequence of key-value pairs into a dictionary of lists.

Leave a Comment