>> I am learning python. >> >> if I have a csv file, like this >> banana,4.0 >> apple,3.5 >> orange,3.0 >> >> Can anyone show me how to read the csv file line by line and then >> create a dictionary to contain these keys and values?
with open('data.csv') as f: data = dict([[l.strip() for l in line] for line in csv.reader(f)]) data {'apple': '3.5', 'banana': '4.0', 'orange': '3.0'} -- https://mail.python.org/mailman/listinfo/python-list