I have a .csv file which looks like below:
A,3
B,2
C,5
D,1
I want to store the above values in a dictionary where an alphabet is the key. My code is below:
reader11 = csv.reader(open('file.csv'))
for row in reader11:
if row and row[0]:
excount[row[0]]=[i for i in row[1] if i]
print excount.items()
excount
is:
[('A', ['3']), ('B', ['2']), ('C', ['5']), ('D', ['1'])]
The numbers are stored as strings in excount
. How do I store them as numbers(like below)?
[('A', [3]), ('B', [2]), (C, [5]), ('D', [1])]