fd=open("file.txt","r") d=fd.read() fd.close() m=d.split(" ") s=" ".join(m[:-1]) fd=open("file.txt","w+") for i in range(len(s)): fd.write(s[i]) fd.close()