Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions palindrome_checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# palindrome_checker.py
def is_palindrome(s):
return s == s[::-1]
# Normalize the string: convert to lowercase and filter out non-alphanumeric characters
filtered_s = ''.join(c.lower() for c in s if c.isalnum())

# Use two-pointer technique to check for palindrome
left, right = 0, len(filtered_s) - 1
while left < right:
if filtered_s[left] != filtered_s[right]:
return False
left += 1
right -= 1
return True

if __name__ == "__main__":
word = input("Enter a word: ")
Expand Down