Sudipta Swarnakar Sudipta Swarnakar - 1 month ago 11
Python Question

Convert csv file into python dictionary

I want to convert

type CSV file into a dictionary having format like


For an input.csv CSV file holding:


This could be done as follows:

import csv

my_dict = {}

with open('input.csv') as f_input:
    for row in csv.reader(f_input):
        my_dict[row[0]] = {row[1] : row[2]}

print my_dict

Giving you:

{'A': {'B': '24'}}