python 3.x - create a dictionary from a csv file -
my csv program studentid,firstname,midterm,final,total,grade 20135447,delta,47.00,37.00,65.00,dc 20144521,jeffrey,36.00,22.00,27.60,ff
l tried code
with open('marks.csv')as file: line=csv.reader(file) mydict={rows[0]:rows[1:] rows in line} print(mydict)
l got following traceback error traceback (most recent call last): file "", line 3, in file "", line 3, in indexerror: list index out of range
but desired output {20135447:['delta','47.00','37.00','65.00','dc'], '20144521':['jeffrey','36.00','22.00','27.60','ff']}
please me
import csv mydic = dict() open('marks.csv') myfile: line = csv.reader(myfile) row in line: mydic[row[0]] = row[1:]
Comments
Post a Comment