I have to make a program that tests if an input string is a palindrome. A palindrome is a sequence of words that reads the same as the sequence in reverse, such as the word 'noon'. The program requirements are as follows:
- You must use a stack
- The program should ignore all characters other than letters.
- Input from file
- Test single words and complete sentences
- There should be some true false results.
Here is my code so far:
f = open('myTextFile.txt', "r")
line = f.readline()
while line:
print(line)
line = f.readline()
exclude = set("-")
line = ''.join(ch for ch in line if ch not in exclude)
exclude = set(",")
line = ''.join(ch for ch in line if ch not in exclude)
exclude = set(".")
line = ''.join(ch for ch in line if ch not in exclude)
exclude = set(" ")
line = ''.join(ch for ch in line if ch not in exclude)
f.close()
My question is what to do next, I'm kind of lost, I removed all the extra characters, should I put each line into a list to work with them separately? Can you just guide me in the right direction?