From d8a4faf96d940737ddc488aa8817bc3563ab1a82 Mon Sep 17 00:00:00 2001 From: Ashwin Das Date: Fri, 22 May 2020 15:27:23 +0530 Subject: [PATCH] Update is_palindrome.py (#2025) * Update is_palindrome.py * Update is_palindrome.py * Reuse s Co-authored-by: Christian Clauss --- strings/is_palindrome.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/strings/is_palindrome.py b/strings/is_palindrome.py index 3070970ca..a0795b7b3 100644 --- a/strings/is_palindrome.py +++ b/strings/is_palindrome.py @@ -1,4 +1,4 @@ -def is_palindrome(s): +def is_palindrome(s: str) -> bool: """ Determine whether the string is palindrome :param s: @@ -7,7 +7,16 @@ def is_palindrome(s): True >>> is_palindrome("Hello") False + >>> is_palindrome("Able was I ere I saw Elba") + True + >>> is_palindrome("racecar") + True + >>> is_palindrome("Mr. Owl ate my metal worm?") + True """ + # Since Punctuation, capitalization, and spaces are usually ignored while checking Palindrome, + # we first remove them from our string. + s = "".join([character for character in s.lower() if character.isalnum()]) return s == s[::-1]