Frequency of values
Write a Python program to count how often each value appears in a dictionary.
{"a": 10, "b": 20, "c": 25, "d": 10, "e": 30, "f": 20}{10: 2, 20: 2, 25: 1, 30: 1}Approach
Counter(d.values()).
Solution
from collections import Counterd = {"a": 10, "b": 20, "c": 25, "d": 10, "e": 30, "f": 20}print(dict(Counter(d.values()))){10: 2, 20: 2, 25: 1, 30: 1}Learn the concept
New to this topic? Read the lesson, then come back.