
Ich schaffe es nicht eine Baum zu erstellen. Hab folgende Daten:
Code: Alles auswählen
data = [
{'shortcut': 'Index', 'id': 1L, 'parent': 0L},
{'shortcut': 'Elementary', 'id': 13L, 'parent': 10L},
{'shortcut': 'OldDefault', 'id': 12L, 'parent': 10L},
{'shortcut': 'SourceCode', 'id': 7L, 'parent': 2L},
{'shortcut': 'RSS', 'id': 6L, 'parent': 2L},
{'shortcut': 'SmallWhite', 'id': 14L, 'parent': 10L},
{'shortcut': 'SmallDark', 'id': 11L, 'parent': 10L},
{'shortcut': 'Designs', 'id': 10L, 'parent': 0L},
{'shortcut': 'TinyTextileExample', 'id': 3L, 'parent': 2L},
{'shortcut': 'ExamplePages', 'id': 2L, 'parent': 0L},
{'shortcut': 'Contact', 'id': 5L, 'parent': 2L},
{'shortcut': 'SiteMap', 'id': 4L, 'parent': 2L},
{'shortcut': '3.Ebene', 'id': 15L, 'parent': 3L},
]
Code: Alles auswählen
sitemap = [
{'parent': 0L, 'id': 1L, 'shortcut': 'Index'},
{
'parent': 0L, 'id': 10L, 'shortcut': 'Designs',
'subitems': [
{'parent': 10L, 'id': 13L, 'shortcut': 'Elementary'},
{'parent': 10L, 'id': 12L, 'shortcut': 'OldDefault'},
{'parent': 10L, 'id': 14L, 'shortcut': 'SmallWhite'},
{'parent': 10L, 'id': 11L, 'shortcut': 'SmallDark'}
]
},
{
'parent': 0L, 'id': 2L, 'shortcut': 'ExamplePages',
'subitems': [
{'parent': 2L, 'id': 7L, 'shortcut': 'SourceCode'},
{'parent': 2L, 'id': 6L, 'shortcut': 'RSS'},
{
'parent': 2L, 'id': 3L, 'shortcut': 'TinyTextileExample',
'subitems': [
{'parent': 3L, 'id': 15L, 'shortcut': '3.Ebene'},
]
},
{'parent': 2L, 'id': 5L, 'shortcut': 'Contact'},
{'parent': 2L, 'id': 4L, 'shortcut': 'SiteMap'}
]
}
]
Jemand eine Idee, wie man das macht? Ist IMHO eine Allgemeine Fragestellung. Geht wohl irgendwie rekursiv.
Was ähnliches hatten wir hier: http://www.python-forum.de/topic-7501.html Hilft mir aber gerade nicht so weiter...
EDIT: Ha, ich hab was: [EDIT2: Alte Version gelöscht]