csv library python convert dict to csv
import csv
my_dict = {'1': 'aaa', '2': 'bbb', '3': 'ccc'}
with open('test.csv', 'w') as f:
for key in my_dict.keys():
f.write("%s,%sn"%(key,my_dict[key]))
csv library python convert dict to csv
import csv
my_dict = {'1': 'aaa', '2': 'bbb', '3': 'ccc'}
with open('test.csv', 'w') as f:
for key in my_dict.keys():
f.write("%s,%sn"%(key,my_dict[key]))
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