I know this is first year computer science stuff, but it can be fun to play with.
Suppose you want a simple, general purpose function to find palindromes. Here’s what I came up with; we’ll name it “ispal.py”:
#!/usr/bin/python
import sys
import re
q = sys.argv[1]
q = re.sub(”(\s+|’|\.|\,|\!|\?|\:|\;)”, “”, q).lower()
print q==q[::-1]
Line by line, it’s pretty simple.
Continue reading ‘Detecting Palindromes With Python, Revisited’
