From 4daef2ae11e747b2e3e651b49cfdad209ed0bda7 Mon Sep 17 00:00:00 2001 From: G-type <162748908+gtref@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:35:56 +1300 Subject: [PATCH] is_palindrome now supports punctuation and does not return false for A man, a plan, a canal: Panama Signed-off-by: G-type <162748908+gtref@users.noreply.github.com> --- fixit/textutils.py | 8 +++++++- tests/test_textutils.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fixit/textutils.py b/fixit/textutils.py index ce615a0..76ecbdf 100644 --- a/fixit/textutils.py +++ b/fixit/textutils.py @@ -8,7 +8,13 @@ def is_palindrome(text: str) -> bool: is_palindrome("madam") returns True. is_palindrome("hello") returns False. """ - return text == text[::-1] + + cleaned = "".join( + ch.lower() + for ch in text + if ch.isalnum() + ) + return cleaned == cleaned[::-1] def reverse_words(text: str) -> str: diff --git a/tests/test_textutils.py b/tests/test_textutils.py index a51a607..58fe2ce 100644 --- a/tests/test_textutils.py +++ b/tests/test_textutils.py @@ -11,7 +11,6 @@ def test_palindrome_ignores_case(): assert is_palindrome("Level") -@pytest.mark.xfail(reason="Known bug: spaces and punctuation are not ignored") def test_palindrome_ignores_punctuation(): assert is_palindrome("A man, a plan, a canal: Panama")