I need to change the format of a list following a tree structure where a parent can have multiple children (not a binary tree).
(我需要在一个树结构下更改一个列表的格式,在该树结构中,一个父母可以有多个孩子(而不是二叉树)。)
My list follow this structure: [an object, a player, my_id, my_parent_id]
(我的列表遵循以下结构: [an object, a player, my_id, my_parent_id]
)
What I want:
(我想要的是:)
[an object, a player, my_id, my_parent_id, [my children, [my
grandchildren, [...]]]]
I could make a program to format like this but I wanted to know if there are already any way to do this.
(我可以制作一个程序来格式化,但是我想知道是否已有任何方法可以这样做。)
Here is the output of my application:
(这是我的应用程序的输出:)
[[<__main__.Nim object at 0x013FDBD0>, 'Human', 0, 0], [<__main__.Nim object at 0x014CDAD0>, 'Bot', 1, 0], [<__main__.Nim object at 0x014CDAF0>, 'Bot', 2, 0], [<__main__.Nim object at 0x014CDB90>, 'Bot', 3, 0], [<__main__.Nim object at 0x014CDBD0>, 'Bot', 4, 0], [<__main__.Nim object at 0x014CDC50>, 'Bot', 5, 0], [<__main__.Nim object at 0x014CDC10>, 'Human', 6, 5]]
What I want :
(我想要的是 :)
[[<__main__.Nim object at 0x013FDBD0>, 'Human', 0, 0, [<__main__.Nim object at 0x014CDAD0>, 'Bot', 1, 0], [<__main__.Nim object at 0x014CDAF0>, 'Bot', 2, 0], [<__main__.Nim object at 0x014CDB90>, 'Bot', 3, 0], [<__main__.Nim object at 0x014CDBD0>, 'Bot', 4, 0], [<__main__.Nim object at 0x014CDC50>, 'Bot', 5, 0, [<__main__.Nim object at 0x014CDC10>, 'Human', 6, 5]]]
Thank you in advance.
(先感谢您。)
ask by Sourou Cerulean translate from so