Does anyone know how to get info from a csv?

Simple, you can use the csv module

for example, have the following csv file

a,1
b,7
c,5
d,2
e,6
>>> import csv
>>> filename = "/Users/sunnky/Desktop/test.csv"
>>> d = {}
>>> with open(filename, mode="r", encoding='utf-8-sig') as f:
...     reader = csv.reader(f)
...     for k, v in reader:
...             d[k] = v
...
>>> new_d = sorted(d.items(), key = lambda m: m[1])
>>> min, max = new_d[0], new_d[len(new_d)-1]
>>> print(min, max)
('a', '1') ('b', '7')

Browse More Popular Posts

Leave a Comment