@amasad/

CSV Example

Python

No description

fork
loading
Files
  • main.py
  • books.csv
main.py
1
2
3
4
5
6
7
8
9
import csv
import operator

print('Books sorted by date:\n')
with open('books.csv', newline='') as csvfile:
	books = csv.reader(csvfile, delimiter=',')
	sortedBooks = sorted(books, key=operator.itemgetter(1), reverse=True)
	for title, year, author in sortedBooks:
	    print(title, 'by', author, year)