Python - Palindrome Checker
Python - Palindrome Checker
Submitted by Corey Goldberg on Sun, 02/03/2008 - 16:15.A palindrome is a sequence that reads the same in either direction.
Here is function I wrote to check if a phrase is a palindrome:
import re def is_palindrome(txt): txt = re.sub('\W+',
'', txt).lower() return txt == txt[::-1]
phrase = "Go hang a salami, I'm a lasagna hog" print
is_palindrome(phrase) >> True 