python create dictionary from csv
mydict = {y[0]: y[1] for y in [x.split(",") for x in open('file.csv').read().split('n') if x]}
python create dictionary from csv
mydict = {y[0]: y[1] for y in [x.split(",") for x in open('file.csv').read().split('n') if x]}
Convert csv to dictionary in Python
pythonCopyimport csv
mydict = {}
with open('csv_file.csv', mode='r') as inp:
reader = csv.reader(inp)
dict_from_csv = {rows[0]:rows[1] for rows in reader}
print(dict_from_csv)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us