collections.Counter

Lab Python Intermediate 20 points

Read a line of text and print the 3 most common letters (ignore case and non-letters) as letter count; ties alphabetical.

Input

One line.

Output

Up to 3 lines.

Example

Input

Hello, World!

Output

l 3
o 2
d 1
Sample input available Sample output available
Editor
Python

Hints

Counter counts items in any iterable.

most_common() orders ties by first appearance, so sort yourself for alphabetical ties.

Solution explanation

Counter is a dict subclass for counting, with handy methods like most_common.

Show solution
from collections import Counter

counts = Counter(ch for ch in input().lower() if ch.isalpha())
for letter, count in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))[:3]:
    print(letter, count)
Output
Answer
HOME LEARN COMMUNITY DASHBOARD