Convert lines of string to a dictionary

3

I have an initial code like this:

record = "Jane,Doe,25/02/2002;
          James,Poe,19/03/1998;
          Max,Soe,16/12/2001
          ..."

I need to make it into a dictionary and its output should be something like this:

{'First name': 'Jane', 'Last name': 'Doe', 'Birthday': '25/02/2002'}
{'First name': 'James', 'Last name': 'Poe', 'Birthday': '19/03/1998'}
...

Each line should have an incrementing key starting from 1.

I currently have no idea to approach this issue as I am still a student with no prior experience.

I have seen people use this for strings containing key-value pairs but my string does not contain those:

mydict = dict((k.strip(), v.strip()) for k,v in 
              (item.split('-') for item in record.split(',')))
Share
Improve this question

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue