Python Practice › Dictionary Programs › Program 35
Letter frequency with Counter
Write a Python program to create a dictionary of letter counts from a string.
Input
"sqatools"
Output
{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}Approach
Counter(text).
Solution
from collections import Counterprint(dict(Counter("sqatools")))Output
{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}Learn the concept
New to this topic? Read the lesson, then come back.