77 961
Assignments Done
98,4%
Successfully Done
In August 2019

Answer to Question #52369 in Python for Oz

Question #52369
A text file named input.txt contains zero or more words in each line. Write a program that reads the above file and creates a file named output.txt with all the words appearing in the input, but with exactly one word per line. The input file may be empty.
Expert's answer
"""Example of input:
abc
def ge
Example of output:
abc
def
ge
"""
fid = open("output.txt", 'w');
# read all lines in file
with open("input.txt") as f:
lines = f.readlines();
# iterate by lines
for line in lines:
words = line.split();
if len(words) > 0:
for word in words:
fid.write(word + "\n");
fid.close();

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions