Drill

ProblemsPython › warmup

Are these two an anagram

mediumwarmupPython

A word game checks whether one phrase uses exactly the same letters as another.

is_anagram(text: string, other: string) → bool

Solve it in the editor →

Where you start

def is_anagram(text: str, other: str) -> bool:
    

Worked examples

CallResult
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)

The same problem in another language

More warmup problems in Python