K
Ksenia Marasanova
I get this kind of list from a database. (The tuple structure is: id,
name, parent_id)
[(1, 'grandparent', None), (2, 'parent', 1), (3, 'otherparent', 1), (4,
'child', 3)]
I would like to transfer it (in Python) into a tree structure. I don't
care much about format, as long as I'll be able to get all the
information, based on one id. For example, if I have id=3, I want to
get
- name ('otherparent')
- children (one child, with id=4, name='child')
- parent id
Any tips? Recipes? ;-)
Thanks,
Ksenia.
name, parent_id)
[(1, 'grandparent', None), (2, 'parent', 1), (3, 'otherparent', 1), (4,
'child', 3)]
I would like to transfer it (in Python) into a tree structure. I don't
care much about format, as long as I'll be able to get all the
information, based on one id. For example, if I have id=3, I want to
get
- name ('otherparent')
- children (one child, with id=4, name='child')
- parent id
Any tips? Recipes? ;-)
Thanks,
Ksenia.