From: Ron Adam (radam2_at_tampabay.rr.com)
Date: Fri, 14 Nov 2003 11:51:02 GMT
On Thu, 13 Nov 2003 17:32:06 +0000, Alan Kennedy <firstname.lastname@example.org>
>I'm not too happy with it though. There must be some way to have a
>single fixed regular expression that can be used to test every
Thought I'd give it a try too. This is what I came up with. I used
the regular expression re.sub() function to remove the punctuation and
The really hard part was trying to come up with a palindrome that has
the word python in it. :-)
Test if a string is a palindrome.
p = p.lower()
p = re.sub(r'\W','',p)
if p[:1] == p[-1:]:
p = p[1:-1]
if (len(p) <= 1):
palindrome_list = ["Bolton",
"No 'H' type, mate. No spot stops one tame
"A man, a plan, a cat, a ham, a yak, a yam, a hat,
"Was it a car or a cat I saw?",
"This is not a palindrome!"]
for p in palindrome_list:
print 'is a palindrome.'
print 'is not a palindrome.'