I need to create a dictionary from a text file that contains comma-separated values.
So far I wrote this much.
import csv
pick = open('a.txt','r')
read = csv.reader(pick)
reviews = {}
The sample data in the text file looks like this
Peter,Gravity,4.5,For a Few Dollars More,1.0,Prometheus,4.0
Jack Holmes,Lawrence of Arabia,3.0,Gravity,3.5,The Godfather,1.5,Prometheus,5.0,The Guns of Navarone,3.0
And I want to create a dictionary that should look like this
{'Peter': {'Gravity': 4.5,
'For a Few Dollars More': 1.0,
'Prometheus': 4.0},
'Jack Holmes': {'Lawrence of Arabia': 3.0,
'Gravity': 3.5,
'The Godfather': 1.5,
'Prometheus': 5.0,
'The Guns of Navarone': 3.0,}
}
I looked on these pages: this
this
this
this but didn't help to answer my question.
Could you give me some hints or ideas on how to accomplish this?
was a typo. No there won't be a
at the end of each line. – 007mrviper Apr 18 '20 at 03:21