How to display the contents of text file in reverse order?
Answers
Answered by
2
Answer:
Use reversed() to read a file line by line backwards
Call open(filename, mode) with "r" as mode to read filename as a stream. Call file. readlines() with this stream asfile to return a list containing each line of the file. Call reversed(list) to reversethe contents of list .
Answered by
5
Python Program to Read the Contents of a File in Reverse Order
- Take the file name from the user.
- Read each line from the file using for loop and store it in a list.
- Print the elements of list in reverse order.
- Exit.
Similar questions
Physics,
6 months ago
Science,
6 months ago
Chemistry,
6 months ago
Computer Science,
11 months ago
Math,
1 year ago