Drill

ProblemsPython › warmup

Palindrome check

easywarmupPython

A puzzle feature checks whether a phrase reads the same backwards.

is_palindrome(text: string) → bool

Solve it in the editor →

Where you start

def is_palindrome(text: str) -> bool:
    

Worked examples

CallResult
is_palindrome("")True
is_palindrome("racecar")True
is_palindrome("A man, a plan, a canal: Panama")True
is_palindrome("hello")False

Hint

Walk one index from each end, skipping anything that is not alphanumeric.

Reference solution in Python
def is_palindrome(text: str) -> bool:
    s = [c for c in text.lower() if c.isalnum()]
    return s == s[::-1]

The same problem in another language

More warmup problems in Python