def pali(s): n = len(s) result = True for i in range(n//2): if s[i] != s[-i-1]: result = False return(result) mf1 = open("/Users/koc/Desktop/next.txt", "r") for s in mf1: t = s[0:len(s)-1] print(t) mf1 = open("/Users/koc/Desktop/next.txt", "r") mw1 = open("/Users/koc/Desktop/xyz1.txt", "w") for s in mf1: mw1.write(s) mw1.close() mf2 = open("/Users/koc/Desktop/words.txt", "r") mw2 = open("/Users/koc/Desktop/xyz2.txt", "w") for s in mf2: t = s[0:len(s)-1] if pali(t): mw2.write(s) mw2.close()