File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ """Palindrome Checker.
2+
3+ This module contains functions to check if a string is a palindrome.
4+ A palindrome is a word, phrase, or sequence that reads the same backward as forward.
5+ """
6+
7+
8+ def is_palindrome (text : str ) -> bool :
9+ """
10+ Check if a given string is a palindrome.
11+
12+ A palindrome is a string that reads the same forward and backward,
13+ ignoring case, spaces, and punctuation.
14+
15+ Args:
16+ text: The string to check
17+
18+ Returns:
19+ True if the string is a palindrome, False otherwise
20+
21+ Examples:
22+ >>> is_palindrome("racecar")
23+ True
24+ >>> is_palindrome("hello")
25+ False
26+ >>> is_palindrome("A man a plan a canal Panama")
27+ True
28+ >>> is_palindrome("race a car")
29+ False
30+ >>> is_palindrome("")
31+ True
32+ >>> is_palindrome("a")
33+ True
34+ >>> is_palindrome("Madam")
35+ True
36+ """
37+ # Remove non-alphanumeric characters and convert to lowercase
38+ cleaned = "" .join (char .lower () for char in text if char .isalnum ())
39+ # Check if the cleaned string equals its reverse
40+ return cleaned == cleaned [::- 1 ]
41+
42+
43+ if __name__ == "__main__" :
44+ import doctest
45+
46+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments