Skip to content

Commit b8b6346

Browse files
cclaussgithub-actionspre-commit-ci[bot]CaedenPH
authored
My favorite palindrome (TheAlgorithms#7455)
* My favorite palindrome * updating DIRECTORY.md * Update is_palindrome.py * Update is_palindrome.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update strings/is_palindrome.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * Update is_palindrome.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
1 parent 0dc95c0 commit b8b6346

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

strings/is_palindrome.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
def is_palindrome(s: str) -> bool:
22
"""
3-
Determine whether the string is palindrome
4-
:param s:
5-
:return: Boolean
6-
>>> is_palindrome("a man a plan a canal panama".replace(" ", ""))
3+
Determine if the string s is a palindrome.
4+
5+
>>> is_palindrome("A man, A plan, A canal -- Panama!")
76
True
87
>>> is_palindrome("Hello")
98
False
@@ -14,15 +13,15 @@ def is_palindrome(s: str) -> bool:
1413
>>> is_palindrome("Mr. Owl ate my metal worm?")
1514
True
1615
"""
17-
# Since Punctuation, capitalization, and spaces are usually ignored while checking
18-
# Palindrome, we first remove them from our string.
19-
s = "".join([character for character in s.lower() if character.isalnum()])
16+
# Since punctuation, capitalization, and spaces are often ignored while checking
17+
# palindromes, we first remove them from our string.
18+
s = "".join(character for character in s.lower() if character.isalnum())
2019
return s == s[::-1]
2120

2221

2322
if __name__ == "__main__":
24-
s = input("Enter string to determine whether its palindrome or not: ").strip()
23+
s = input("Please enter a string to see if it is a palindrome: ")
2524
if is_palindrome(s):
26-
print("Given string is palindrome")
25+
print(f"'{s}' is a palindrome.")
2726
else:
28-
print("Given string is not palindrome")
27+
print(f"'{s}' is not a palindrome.")

0 commit comments

Comments
 (0)