Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- source = [
- (None, 'a'),
- (None, 'b'),
- (None, 'c'),
- ('a', 'a1'),
- ('a', 'a2'),
- ('a2', 'a21'),
- ('a2', 'a22'),
- ('b', 'b1'),
- ('b1', 'b11'),
- ('b11', 'b111'),
- ('b', 'b2'),
- ('c', 'c1'),
- ]
- a = {}
- def appending(root_id, child_name, a):
- if root_id in a:
- a[root_id][child_name] = {}
- else:
- for el in a:
- el = appending(root_id, child_name, a[el])
- return a
- for el in source:
- if not el[0]:
- a[el[1]] = {}
- else:
- a = appending(el[0], el[1], a)
- print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement