how to create a dictionary from csv file?

Tim Chase python.list at tim.thechases.com
Tue Apr 26 10:36:59 EDT 2016


On 2016年04月26日 07:18, +dime+ wrote:
> 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?

import csv
with open('data.csv') as f:
 data = dict(csv.reader(f))
Hard to get much more straight-forward.
-tkc


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /