def mastework(id_key, id_value):
id_join = {}
for k, v in zip(id_key, id_value):
id_join[k] = id_join.get(k, []) + [v]
return {k:v if len(v) > 1 else v[0] for k, v in id_join.items()}
Пример:
ID_Masterok = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ID_Master = ['Интендификатор мастера', '654', '2425', '654', '654', '—', '—', '—', '—', '—', '—']
ID_Mastework = mastework(ID_Master, ID_Masterok)
print(ID_Mastework)
In [55]:
{'Интендификатор мастера': 0, '654': [1, 3, 4], '2425': 2, '—': [5, 6, 7, 8, 9, 10]}