Skip navigation.

Python - Palindrome Checker

Python - Palindrome Checker

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