ich versuche eine liste geordnet in ein dict zu übernehmen.
rate mal, ob das klappt? NEIN, klappt natürlich nicht!!!
ich versuche, das ergebnis von result_dict zu erhalten:
Code: Alles auswählen
lst = [['Niederlassungen', 'Spalte', [4, 0, '']],
['Niederlassungen', 'Doppelpunkt', [4, 1, '040']],
['Niederlassungen', 'Doppelpunkt', [4, 2, '1020']],
['Tabelle11', 'Notation', [0, 0, ':']],
['Tabelle11', 'Notation', [0, 1, ':']],
['Tabelle11', 'Spalte', [0, 2, '']]
]
result_dict = {'Niederlassungen': {'Spalte': [[4, 0, '']],
'Doppelpunkt': [[4, 1, '040'], [4, 2, '1020']]
},
'Tabelle11': {'Notation': [[0, 0, ':'], [0, 1, ':']],
'Spalte': [[0, 2, '']]
}
}
print(result_dict)
print('---')
fail_dict = {}
# fail_dict['dict1'] = {}
# fail_dict['dict1']['innerkey'] = 'value'
for lst_element in lst:
sheet = lst_element[0]
fail_name = lst_element[1]
fail_values = lst_element[2]
if sheet not in fail_dict.keys():
fail_dict[sheet] = {}
if fail_name not in fail_dict.values():
fail_dict[sheet][fail_name] = fail_values
else:
if fail_name not in fail_dict[sheet].values():
fail_dict[sheet][fail_name] = fail_values
else:
fail_dict[sheet][fail_name].append(fail_values)
print(fail_dict)