Frequency of values

EasyDictionary Programs · 74 of 94

Write a Python program to count how often each value appears in a dictionary.

Advertisement
Input
{"a": 10, "b": 20, "c": 25, "d": 10, "e": 30, "f": 20}
Output
{10: 2, 20: 2, 25: 1, 30: 1}

Approach

  1. Counter(d.values()).

Solution

Python
from collections import Counterd = {"a": 10, "b": 20, "c": 25, "d": 10, "e": 30, "f": 20}print(dict(Counter(d.values())))
Output
{10: 2, 20: 2, 25: 1, 30: 1}
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs