Count frequencies in a list using a dictionary.

In this python dictionary program, we will count frequencies in a list using a dictionary.

Steps to solve the program
  1. Take a list as input and create an empty dictionary.
  2. Use for loop to iterate over elements in the list.
  3. Add the element as key and its occurrences in the list as its value.
  4. Use count() for this purpose.
  5. Print the output.
				
					list1 = [2,5,8,1,2,6,8,5,2]
dict1 = {}

for val in list1:
    dict1[val] = list1.count(val)
    
print(dict1)
				
			

Output :

				
					{2: 3, 5: 2, 8: 2, 1: 1, 6: 1}
				
			

print the given dictionary in the form of tables.

find mean of values of keys in a dictionary.

Leave a Comment