Say I have a text file like this (test.txt):
This is a
test
my python code:
f = open("test.txt")
x = f.readlines()
s = []
for i in x:
k = i.replace("a","not a")
s.append(k)
with open('output.txt', 'w') as a:
a.write(" ".join(s))
gives the following (output.txt):
This is not a
test
but I do not want the whitespace in between. I want something like this:
This is not a test
How can I remove the newline?