i am trying to read a comma delimited file and convert it into a dictionary so that it ends up in the following format
{'CpE' : CSE 2315,'CpE' : 'CSE 2320'. 'CpE' : 'CSE 2441'..........,'CS' : CSE 2315, 'CS' : CSE 2320}
so all i want to do is store each line in a dictionary with the degree being the key, and the class being the value
the file being read is
CpE,CSE 2315
CpE,CSE 2320
CpE,CSE 2441
CpE,CSE 3320
CpE,CSE 3442
CpE,EE 2440
CpE,MATH 1426
CS,SE 2315
CS,CSE 2320
CS,CSE 3320
CS,CSE 4303
CS,CSE 4305
CS,CSE 4308
CS,MATH 1426
the code i wrote to try to do this is... fp being the file
majors = {}
for line in fp :
(degree, course) = line.strip().split(',')
majors[degree] = course
print majors
what i get is
{'CS': 'MATH 1426', 'CpE': 'MATH 1426'}
it seems its only grabbing the last value of each degree/key. why?