![]() |
VOOZH | about |
Given a text file. The task is to reverse as well as stores the content from an input file to an output file. This reversing can be performed in three ways.
Example: Full Reversing
Input:
Hello Geeks
for geeks!
Output:
!skeeg rof
skeeG olleH
Example 2: Line-wise Reversing
Input:
Hello Geeks
for geeks!Output:
for geeks!
Hello Geeks
Example 3: Word to word reversing
Input:
Hello Geeks
for geeks!
Output:
Geeks Hello
geeks! for
This method reads the entire file as a single string and reverses it using Python slicing. It is simple and fast but not suitable for very large files due to memory usage.
Output
Explanation:
This approach reverses the order of lines instead of characters. It reads all lines into a list and reverses the list.
Output
Explanation:
This method reverses words in each line while keeping line order intact. Useful when sentence structure must be preserved.
Output
Explanation: