Challenge 10: Check If a String Is a Palindrome

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

  1. The input must be a string.
  2. Ignore:
    • Spaces
    • Letter casing
  3. Return True if the text is a palindrome, otherwise return False.
  4. Raise a TypeError if 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.

Python Challenge 10 Solution Check if a string is a palindrome
Python Challenge 10 Solution Check if a string is a palindrome

Python Challenge 10 Test Check if a string is a palindrome

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)

  1. Reverse string
  2. Count words
  3. Find max
  4. Character frequency
  5. Filter even numbers
  6. Even or odd
  7. Sum numbers
  8. Remove duplicates
  9. Second largest
  10. 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.