A palindrome is a word or phrase that reads the same forwards and backwards after normalization.
This challenge looks simple at first—but solving it properly requires careful thinking about input cleanup, assumptions, and edge cases.
It also connects nicely back to earlier string challenges in the series.
Your Task
Write a function that checks whether a given string is a palindrome.
def is_palindrome(text: str) -> bool:
…
Rules
- The input must be a string.
- Ignore:
- Spaces
- Letter casing
- Return
Trueif the text is a palindrome, otherwise returnFalse. - Raise a
TypeErrorif the input is not a string.
Examples
is_palindrome("racecar") → True
is_palindrome("RaceCar") → True
is_palindrome("Never odd or even") → True
is_palindrome("hello") → False
Invalid Input Examples
is_palindrome(123) → TypeError
is_palindrome(None) → TypeError
is_palindrome(["a", "b"]) → TypeError
Hints (Optional)
- Normalize the string before checking.
- Think about what should be ignored and what should not.
- A reversed string comparison is often enough—once the input is cleaned.


What These Tests Enforce
✔️ Case-insensitive comparison
✔️ Spaces ignored
✔️ Empty string handled correctly
✔️ Clear distinction between valid and invalid input
✔️ Predictable failure for unsupported cases
What This Challenge Teaches
- String normalization
- Defensive programming
- Reusing previous concepts
- Writing clear boolean logic
- Handling edge cases explicitly
Bonus Challenges
- Ignore punctuation (e.g. commas, periods)
- Support Unicode characters
- Solve the problem without reversing the string
- Count how many palindromes appear in a list of strings
Why This Matters
Real-world text is messy.
Learning to normalize input before applying logic is a core programming skill—and one that shows up everywhere from data processing to security.
Progression Check (You’re Doing This Right)
- Reverse string
- Count words
- Find max
- Character frequency
- Filter even numbers
- Even or odd
- Sum numbers
- Remove duplicates
- Second largest
- Palindrome check ✅
This feels like a complete beginner foundation set now.
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
👉Next Challenge → Merge Two Dictionaries (Safely)
Want more practical Python challenges?
Subscribe to the Solve With Python newsletter and get new problems delivered to your inbox.