Advertisement
daniilak

Untitled

Jan 5th, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1.  
  2. source = [
  3. (None, 'a'),
  4. (None, 'b'),
  5. (None, 'c'),
  6. ('a', 'a1'),
  7. ('a', 'a2'),
  8. ('a2', 'a21'),
  9. ('a2', 'a22'),
  10. ('b', 'b1'),
  11. ('b1', 'b11'),
  12. ('b11', 'b111'),
  13. ('b', 'b2'),
  14. ('c', 'c1'),
  15. ]
  16. a = {}
  17.  
  18. def appending(root_id, child_name, a):
  19. if root_id in a:
  20. a[root_id][child_name] = {}
  21. else:
  22. for el in a:
  23. el = appending(root_id, child_name, a[el])
  24. return a
  25.  
  26. for el in source:
  27. if not el[0]:
  28. a[el[1]] = {}
  29. else:
  30. a = appending(el[0], el[1], a)
  31. print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement