Converting tree list to hierarchy dict

前端 未结 5 1748
日久生厌
日久生厌 2021-02-06 06:39

I have a list of elements with attrs: parent, level, is_leaf_node, is_root_node, is_child_node.

I want to convert this list to hierarchy dict. Example of output dict:

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 07:20

    Everything without a parent is your top level, so make those dicts first. Then do a second pass through your array to find everything with a parent at that top level, etc... It could be written as a loop or a recursive function. You really don't need any of the provided info besides "parent".

提交回复
热议问题