0

Harder problem......

How to reverse a row in CSV file?

1st Oct 2021, 6:46 AM
Sourya Banerjee
Sourya Banerjee - avatar
3 Respostas
+ 6
Sourya Banerjee , SAN , we do not necessarily need the csv module here: import csv with open('/usercode/files/books.txt', 'r') as textfile: for row in reversed(list(csv.reader(textfile))): #', '.join(row) # <<<<< this line of code has no effect as nothing is assigned print(row) we can also do it like this: lst = [] for line in open('/usercode/files/books.txt', 'r'): lst.insert(0, line.strip()) [print(item) for item in lst]
1st Oct 2021, 11:08 AM
Lothar
Lothar - avatar
+ 3
import csv with open('/usercode/files/books.txt', 'r') as textfile: for row in reversed(list(csv.reader(textfile))): ', '.join(row) print(row)
1st Oct 2021, 8:09 AM
SAN
SAN - avatar
+ 1
reverse a single row........SAN
2nd Oct 2021, 3:57 AM
Sourya Banerjee
Sourya Banerjee - avatar