I am trying to read a csv file into a python dictionary (nested)but it's giving me an error saying list index out of range | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I am trying to read a csv file into a python dictionary (nested)but it's giving me an error saying list index out of range

import csv f=open('names.csv','r') reader=csv.reader(f) mydict={row[0]:{'age':row[1],'color':[2]}for row in reader }

1st Nov 2020, 10:15 PM
Simbarashe Mpofu
Simbarashe Mpofu - avatar
1 Answer
+ 1
Give an example of the data you want to read, first 3 lines should suffice. You should access files using "with" like so: with(open('names.csv','r')) as f:
1st Nov 2020, 11:48 PM
Benjamin Jürgens
Benjamin Jürgens - avatar