1
How to associate lists to keys and values to create a dictionary in Python?
Is that the problem? I have a large csv file and I need to read the first line (I turn it into a list) that should be used to associate to the Keys and the following lines should be the values.
An option I imagined would be to use loops for to read each list item and do the assignment. But there is a function / method that does this?
Follows an excerpt of the code, considering only the header (Keys) and the first line (values).
The next step will be to put together a list of dictionaries, each for each line; but this I think I know how to do.
f = open("beatles-diskography.csv", "r")
hd = f.readline()
fl = f.readline()
hd = hd.split(',')
fl = fl.split(',')
c = 0
for s in hd:
s = s.strip()
hd[c] = s
c = c+1
c = 0
for s in fl:
s = s.strip()
fl[c] = s
c = c+1
'''
dic = ???
'''
Elegant code! + 1
– Onilol