Python ProgrammingPython Programming

Creating a dictionary from two lists in Python

people = input_list = [["Richard", [], {"children": "yes", "divorced": "no", "occupation": "analyst"}],
                       ["Mary", ["testing"], {"children": "no", "divorced": "yes", "occupation": "QA analyst", "location": "Seattle"}]]
list_keys = ['name', 'current_project', 'details']
listout = []

for person in people:
    dict_p = {}
    for key in list_keys:
        if not key == 'details':
            dict_p[key] = person[list_keys.index(key)]
        else:
            subdict = person[list_keys.index(key)]
            for subkey in subdict.keys():
                dict_p[subkey] = subdict[subkey]

    listout.append(dict_p)


print(listout)
Output
[{'name': 'Richard', 'current_project': [], 'children': 'yes', 'divorced': 'no', 'occupation': 'analyst'}, {'name': 'Mary', 'current_project': ['testing'], 'children': 'no', 'divorced': 'yes', 'occupation': 'QA analyst', 'location': 'Seattle'}]