Letter frequency with Counter

EasyDictionary Programs · 35 of 94

Write a Python program to create a dictionary of letter counts from a string.

Advertisement
Input
"sqatools"
Output
{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}

Approach

  1. Counter(text).

Solution

Python
from collections import Counterprint(dict(Counter("sqatools")))
Output
{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs