I have a file that contains a word per a line. Each sentence is separated by an empty line. I want to read the file and write the whole words of a sentence on the same line. For example:
This
is
a
sample
input
Hello
World
!!
The desired output is:
This is a sample input
Hello World !!
I try this:
file = open('Words.txt', "r")
Writfile = open('Sent.txt','w')
for line in file:
if line in ['\n']:
Writfile.write('\n')
else:
Writfile.write(line + " ",)