from pathlib import Path

def main():
    data = get_data_to_dict('sample.csv')

    for line in data:
        if line['personnummer'] == '01010111111':
            print(line['medisin'])

def get_data_to_dict(path):
    list_of_lists = get_data(path)
    headers = list_of_lists[0]
    data = list_of_lists[1:]
    col_num = len(headers)

    table = []
    for line in data:
        row_dict = {}
        for i in range(col_num):
            header = headers[i]
            value = line[i]
            row_dict[header] = value
        table.append(row_dict)

    return table
        

def get_data(path):
    file_content = Path(path).read_text(encoding='utf-8')
    new_list = file_content.splitlines()

    table = []
    for row in new_list:
        list_of_elements = row.split(',')
        table.append(list_of_elements)

    return table


if __name__ == '__main__':
    main()