Python Practice › Collections Programs › Program 3
Anagram check with Counter
Write a Python program to check whether two words are anagrams using Counter.
Output
listen silent True python typhon True apple apply False
Approach
- Equal letter counts mean anagrams.
Solution
from collections import Counter for a, b in [("listen", "silent"), ("python", "typhon"), ("apple", "apply")]: print(a, b, Counter(a) == Counter(b))Output
listen silent True python typhon True apple apply False
Learn the concept
New to this topic? Read the lesson, then come back.