Probleme bei dict in dict
Verfasst: Mittwoch 15. Mai 2019, 10:14
Ich versuche, ein Dictionary zu erstellen, in dem die einzelnen Einträge auch wiederum Dictionaries sind.
Dabei habe ich aber ziemliche Probleme, weshalb ich auf Hilfe hoffe.
Ich hoffe, das Problem ergibt sich aus dem Code:
Ausgabe:
Wie kann man Dictionaries ineinanderschachteln?
Dabei habe ich aber ziemliche Probleme, weshalb ich auf Hilfe hoffe.
Ich hoffe, das Problem ergibt sich aus dem Code:
Code: Alles auswählen
dict_list = [['Hallo', 'Wie gehts?', "a", "b", "c"], ['Sortierung im PFS', '1. Knoten', "d", "e", "f"], ['Sortierung im PFS', '2. Knoten', "g", "h", "i"]]
dictionary = {}
dict = {}
for dict_ele in dict_list:
print(str(dict_ele[0]) + " --- " + str(dict_ele[1]) + " --- " + str(dict_ele[2:]))
dict[dict_ele[1]] = dict_ele[2:]
dictionary[dict_ele[0]] = dict[dict_ele[1]]
print('---')
print("Meine Ausgabe: " + str(dictionary))
print("Gewollt: " + str("{'Hallo': {'Wie gehts': ['a', 'b', 'c']}, 'Sortierung im PFS': {'1. Knoten': ['d', 'e', 'f'], '2. Knoten': [['g', 'h', 'i']]}})"))
Code: Alles auswählen
Hallo --- Wie gehts? --- ['a', 'b', 'c']
Sortierung im PFS --- 1. Knoten --- ['d', 'e', 'f']
Sortierung im PFS --- 2. Knoten --- ['g', 'h', 'i']
---
Meine Ausgabe: {'Hallo': ['a', 'b', 'c'], 'Sortierung im PFS': ['g', 'h', 'i']}
Gewollt: {'Hallo': {'Wie gehts': ['a', 'b', 'c']}, 'Sortierung im PFS': {'1. Knoten': ['d', 'e', 'f'], '2. Knoten': [['g', 'h', 'i']]}})