I'm writing a program that checks a txt file with a list of words (one word per line). I'm just this side of done, I think.
def StripPunctuation(s):
answer=""
for c in s:
if c.islower() or c.isupper():
answer=answer+c.lower()
return answer
def Reverse(s):
answer=""
for c in s:
answer=c+answer
return answer
def IsPalindrome(s):
s=StripPunctuation(s)
if s==Reverse(s):
return True
else:
return False
def main():
F=open("wordList.txt","r")
for line in F:
word=line.strip("\n")
if IsPalindrome(word):
print "%s"%word
main()
Instead of a list I just get the last line printed if it's a palindrome. And nothing if it's not. What do I need to add to get the entire list?