Answer to Question #231127 in Python for Rachna Pal

Question #231127

write a python function which create a copy of the file poem.txt as poemrev.txt. this new file contain the data form last word to fist word from the file poem.txt.


1
Expert's answer
2021-09-03T14:05:59-0400
textfile = open("poem.txt")
lines = textfile.readlines()
with open('poemrev.txt', 'w') as f:
    for line in reversed(lines):
        words = line.split()
        words.reverse()
        f.write(' '.join(words))
        f.write('\n')

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