[Tutor] Converting a sequence of dictionaries to a single dictionary
Ek Esawi
esawiek at gmail.com
Tue Jun 21 20:41:08 EDT 2016
Hi All--
I am trying to read a csv file via DictReader and produce a single
dictionary without fieldnames; that is, I just want a single dictionary
that contains tests as keys and grades as values as shown below in my
sample file.
If I loop through the reader, it produces a sequence of 2 entries
dictionaries; each starts with the fieldnames, e.g. {Test:Test1,Grade:A},
etc.
I want to create a single dictionary with only Tests and Grades; that’s
{Test1:A,Test2:b,Test3:c etc.}. I tried several ways but nothing worked.
File
Test Grade
Test1 A
Test2 B
Test3 C
Code;
import csv
with open(Tests.csv, 'r') as Temp:
reader = csv.DictReader(Temp)
More information about the Tutor
mailing list