I have a file with the following structure and a varying number of newlines between the entries:
n Name1 MiddleName1 Surname1
multiline
string1
n Name2 MiddleName2 Surname2
multi
line
string2
n Name3 MiddleName3 Surname3
multiline
string3
How can I read this file into a dictionary which contains:
{"n Name1 MiddleName1 Surname1" : "multiline\nstring1", ...}
I attempted to extract the keys with a regular expression, like so:
with open('file') as infile:
content = infile.read()
match = re.search(r'n .*', content)
But I don't know where to go from there. All similar questions I was able to find have some sort of split (like '=') which can be used to seperate the keys from the objects.