Are these two an anagram
A word game checks whether one phrase uses exactly the same letters as another.
- Case does not matter.
- Whitespace is ignored entirely.
- Everything else — digits, punctuation — counts as a character that has to match.
- Two empty phrases are an anagram of each other.
is_anagram(text: string, other: string) → bool
Where you start
def is_anagram(text: str, other: str) -> bool:
Worked examples
| Call | Result |
|---|---|
is_anagram("Listen", "Silent") | True |
is_anagram("a b", "ba") | True |
is_anagram("hello", "world") | False |
is_anagram("abc", "ab") | False |
Hint
Strip and lowercase both, then compare the sorted characters, or count them.
Reference solution in Python
def is_anagram(text: str, other: str) -> bool:
def clean(s):
return sorted(c for c in s.lower() if not c.isspace())
return clean(text) == clean(other)