You almost have it right.
The file was read in as one big chunk, so s contained the whole file, not just one item.
you needed to strip the line feed off
and notes for other changes below
# Don't need this
#from string import ascii_letters, digits
# s = open("saxo.txt").read()
# read file this way
def ispalendrome(s):
s1 = s.replace(' ', '').lower()
return str(s1) == str(s1)[::-1]
def main():
with open ("saxo.txt") as f:
for s in f:
s = s.strip()
if len(s) > 6:
if ispalendrome(s):
print('{} is a palandrome'.format(s))
else:
print('{} is not a palandrome'.format(s))
main()
# Don't need this
# s = s.lower()
# s = "".join([c for c in s if c in ascii_letters or c in digits])
This line:
s1 = s.replace(' ', '').lower()
compresses the string and makes all characters lower case.
This line:
return str(s1) == str(s1)[::-1]
uses the same logic as you already had, but assures s is a string