0
Harder problem......
How to reverse a row in CSV file?
3 Answers
+ 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]
+ 3
import csv
with open('/usercode/files/books.txt', 'r') as textfile:
for row in reversed(list(csv.reader(textfile))):
', '.join(row)
print(row)
+ 1
reverse a single row........SAN