Screen Link:
My Code:
from csv import reader
open_file = open('users.csv')
read_file = reader(open_file)
data = list(read_file)
data = data[1:]
name_to_email = {data[name] : data[email] for data in range(len(name))}
william_email = name_to_email["William Chase"]
madison_email = name_to_email["Madison Wallace"]
What I expected to happen: I undserstand I did something wrong here, can anyone explain what is missing or i did wrong and how to debug this?
Also in the answer given i am not able to understand why file.close() is used.
Thanks a lot for your help
What actually happened:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-b1c47bd067dc> in <module>
5 data = data[1:]
6
----> 7 name_to_email = {data[name] : data[email] for data in range(len(name))}
8 william_email = name_to_email["William Chase"]
9 madison_email = name_to_email["Madison Wallace"]
<ipython-input-1-b1c47bd067dc> in <dictcomp>(.0)
5 data = data[1:]
6
----> 7 name_to_email = {data[name] : data[email] for data in range(len(name))}
8 william_email = name_to_email["William Chase"]
9 madison_email = name_to_email["Madison Wallace"]
TypeError: 'int' object is not subscriptable