Find the mean of values of keys in a dictionary.

In this python dictionary program, we will find the mean of values of keys in a dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Create two variables named total and count to find the mean of the values.
  3. Use for loop to iterate over values in the dictionary.
  4. Add the value to the total variable and 1 to the count variable.
  5. Find the mean by using the logic.
				
					dict1 = {'m1':25,'m2':20,'m3':15}
total = 0
count = 0

for val in dict1.values():
    total += val
    count += 1
    
print("Mean: ",(total/count))
				
			

Output :

				
					Mean:  20.0
				
			

count frequencies in a list using a dictionary.

convert a list into a nested dictionary of keys.

Leave a Comment