Learning python and having trouble understanding on how to create this function to read a file and return it as a dictionary. I'm aware I need to open the file and then use the .read(), but so far I'm not sure how to sort the data. Since there will be multiple "titles," I'm trying to sort upper-case letters to come before all lower-case. Any advice on how to proceed?
Code I have so far:
def read_text(textname):
d = {}
with open(textname) as f:
for line in f:
(title, year, height, width, media, country) = line.split() # I need to skip the first line in the file as well which just shows the categories.
Text file example:
text0='''"Artist","Title","Year","Total Height","Total
Width","Media","Country"
"Leonardo da Vinci","Mona Lisa","1503","76.8","53.0","oil paint","France"
"Leonardo da Vinci","The Last Supper","1495","460.0","880.0","tempera","Italy"
What I want to return file as:
{'Leonardo da Vinci': [("Mona Lisa",1503,76.8,53.0,"oil paint","France"),
('The Last Supper', 1495, 460.0, 880.0, 'tempera', 'Italy')]}