I have a text file with this contents "one two three four" and I want to create a new text file with one word for each line, like this:
one
two
three
four
I came up with this code:
with open('words.txt','r') as f:
for line in f:
for word in line.split('\n'):
print word
It prints each word in new line, so my question how I can write these words in new file that have one word each line?