It is a very simple parsing exercise, you really should try figure it out yourself.
Here is my solution, using find()
and rfind()
to find the index of the first and last commas to split the lines in blocks. The first and the mid blocks will be used as a key:value pair in a dict. The mid block may require some extra parsing and adjustment, see the code below.
def parse(line):
first = line[:line.find(',')]
last = line[line.rfind(','):]
mid = line.replace(first, '').replace(last, '').strip(',')
#print(first, mid)
if ',' in mid:
mid = mid.strip('"')
mid = mid.split(',')
return {first: mid}
txt = \
'''
keyword,synonym,bidirectional
5487500j,54875,false
76x76,76 x 76,true
feuille,"papier,ramette",false
7843000j,78430,false
'''
r = {}
for line in txt.split('\n'):
if line:
if line.startswith('keyword'):
continue
r.update(parse(line))
print(r)
{'5487500j': '54875', '76x76': '76 x 76', 'feuille': ['papier', 'ramette'], '7843000j': '78430'}