16 lines
590 B
Python
16 lines
590 B
Python
#!/usr/bin/env python3
|
|
"""Palindrome checker - returns 0 if palindrome, 1 otherwise."""
|
|
import sys
|
|
|
|
def is_palindrome(s: str) -> bool:
|
|
"""Check if string is palindrome (ignoring case, non-alphanumeric)."""
|
|
cleaned = ''.join(c.lower() for c in s if c.isalnum())
|
|
return cleaned == cleaned[::-1]
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python3 palindrome.py <string>")
|
|
sys.exit(2)
|
|
result = is_palindrome(sys.argv[1])
|
|
print(f"{sys.argv[1]!r} is {'a palindrome' if result else 'not a palindrome'}")
|
|
sys.exit(0 if result else 1) |