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.
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')
Comments
Leave a comment