Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions R/Reverse Word in a File/Reverse-words-in-file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
filename = input("Enter the filename to read: ")
output_filename = input("Enter the filename to write: ")

with open(filename) as file:
text = file.read()

words = text.split()

with open(output_filename, "w") as file:
for word in words[::-1]:
file.write(word + " ")

print("Words in reverse order written to file successfully.")