In this python dictionary program, we will count the frequency in a dictionary.
Steps to solve the program
- From collections import Counter.
- Take a dictionary as input.
- Pass the values in the dictionary to the Counter and store the result in a variable.
- Print the output.
from collections import Counter
D1 = {'a':10,'b':20,'c':25,'d':10,'e':30,'f':20}
result = Counter(D1.values())
print(result)
Output :
Counter({10: 2, 20: 2, 25: 1, 30: 1})