Challenge: Anagram Check
Completed
Read two words and print anagram if they use exactly the same letters (ignoring capital letters), otherwise not anagram. Count the letters with a dictionary or Counter.
Input
Two lines, one word on each.
Output
anagram or not anagram.
Example
Input
listen silent
Output
anagram
Editor
Python
Hints
Lower-case both words first.
Counter(a) == Counter(b) compares letter counts.
Solution explanation
Counting letters is O(n), faster than sorting both words.
Show solution
from collections import Counter
a = input().strip().lower()
b = input().strip().lower()
print("anagram" if Counter(a) == Counter(b) else "not anagram") Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module