Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def is_palindrome(s: str) -> bool:
cleaned = s.lower().replace(" ", "")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization strips spaces but not other non-alphanumeric characters (punctuation, tabs, hyphens, etc.). The canonical palindrome example "A man, a plan, a canal: Panama" returns False with the current implementation.

If the function is meant to handle natural-language strings, the cleaned step should strip all non-alphanumeric characters instead of just spaces.

Suggested change
cleaned = s.lower().replace(" ", "")
cleaned = "".join(c for c in s.lower() if c.isalnum())
  • Mark as noise

return cleaned == cleaned[::-1]

Loading