Computer Science, asked by RUDEGIRL, 1 year ago

How to display the contents of text file in reverse order?

Answers

Answered by d687cyoyo
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 RUHIADAHIR
5

Python Program to Read the Contents of a File in Reverse Order

  1. Take the file name from the user.
  2. Read each line from the file using for loop and store it in a list.
  3. Print the elements of list in reverse order.
  4. Exit.

Similar questions