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.
1
Expert's answer
2015-05-01T12:24:12-0400
"""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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS