diff --git a/strings/is_palindrome.py b/strings/is_palindrome.py index 4776a5fc2..5758af0ce 100644 --- a/strings/is_palindrome.py +++ b/strings/is_palindrome.py @@ -1,9 +1,8 @@ def is_palindrome(s: str) -> bool: """ - Determine whether the string is palindrome - :param s: - :return: Boolean - >>> is_palindrome("a man a plan a canal panama".replace(" ", "")) + Determine if the string s is a palindrome. + + >>> is_palindrome("A man, A plan, A canal -- Panama!") True >>> is_palindrome("Hello") False @@ -14,15 +13,15 @@ def is_palindrome(s: str) -> bool: >>> 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()]) + # Since punctuation, capitalization, and spaces are often ignored while checking + # palindromes, we first remove them from our string. + s = "".join(character for character in s.lower() if character.isalnum()) return s == s[::-1] if __name__ == "__main__": - s = input("Enter string to determine whether its palindrome or not: ").strip() + s = input("Please enter a string to see if it is a palindrome: ") if is_palindrome(s): - print("Given string is palindrome") + print(f"'{s}' is a palindrome.") else: - print("Given string is not palindrome") + print(f"'{s}' is not a palindrome.")