Palindrome check
A puzzle feature checks whether a phrase reads the same backwards.
- Compare letters and digits only — skip spaces and punctuation.
- Case does not matter.
- An empty string counts as a palindrome.
is_palindrome(text: string) → bool
Where you start
def is_palindrome(text: str) -> bool:
Worked examples
| Call | Result |
|---|---|
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]