I'll go ahead and assume that you're okay with having each dictionary key be associated with the list of matches across all lines in your text file.
What I mean by that is that if personal_data
your dictionary then you would have the following:
>>> personal_data["id"]
[1, 2]
Here is code that builds the dict as necessary. I'm going to omit any code to handle improper formatting and assume every entry has the same keys in the same order, and that groups of values in your text file contain no spaces .
personal_data = {'id':[],'name': [], 'family name': [], 'Birth': []}
keys = list(personal_data.keys())
# this is preferential to using open() and close()
with open('people.txt','r') as file_iterator:
for line in file_iterator:
for entry in line.split(): # assuming fields don't contain spaces
for i, value in enumerate(entry.split(';')):
if i < len(keys): # to prevent IndexErrors in the case of a semicolon at the end
personal_data[keys[i]].append(value)
On my Python 3.9.2 install I get:
{'id': ['1', '2'],
'name': ['Mike', 'Anna'],
'family name': ['Brown', 'Smith'],
'Birth': ['73/04/01', '71/02/01']}
If possible, I think you'd really benefit from modifying the layout of your text file to be more amenable. Namely, splitting entries for each person across lines. Instead of:
1;Mike;Brown;73/04/01; 2;Anna;Smith;71/02/01
you could have:
1;Mike;Brown;73/04/01
2;Anna;Smith;71/02/01
The main motivation for this is it will make it easier to handle values which may have spaces in them like "Maria José", "Sarah Lynn", "dela Cruz". In general, building software which can deal with names can be quite tricky.
As you probably noticed, data like this is quite amenable to tabular formats, like what you'd see in a spreadsheet. Perhaps you'd benefit from putting it in a pandas.DataFrame object? The link takes you to the tutorial in their documentation, which should help you decide if it would be of use.