Just use zip()
to transpose the matrix represented by the csv reader object:
import csv
with open(fn) as f:
reader=csv.reader(f, delimiter='')
a, b, c = zip(*reader)
print a
('Classification Type', 'Commercial Homes', 'Residential Homes')
print b
('A', '12', '10')
print c
('B', '15', '14')
# trim the tuples as you wish, such as b=list(b[1:])...
Then, you may want a dict with the first value of that tuple:
data={}
for t in zip(*reader):
data[t[0]]=t[1:]
print data
# {'A': ('12', '10'), 'B': ('15', '14'), 'Classification Type': ('Commercial Homes', 'Residential Homes')}
Which then can be reduced to a single statement:
data={t[0]:t[1:] for t in zip(*reader)}
# {'A': ('12', '10'), 'B': ('15', '14'), 'Classification Type': ('Commercial Homes', 'Residential Homes')}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…