for line in text.splitlines():
    if line.startswith('school id'):
        school = line.split('=')[1].strip()
headers = None
continue
if school is not None and headers is None:
    headers = line.split('|')
continue
if school is not None and headers is not None and line:
    if not school in data:
        data[school] = []
datum = dict(zip(headers, line.split('|')))
data[school].append(datum)
How can I store data to a data dictionary in Python when headings are in mixed up order