用python的列表构建一棵树
程序员文章站
2022-05-31 08:34:07
...
一 构建树的结构
二 代码
G =['G',[]]
H =['H',[]]
I =['I',[]]
K =['K',[]]
E =['E',[G,H,I,K]]
D =['D',[]]
F =['F',[]]
A =['A',[D,E]]
B =['B',[]]
C =['C',[F]]
Root=['Root',[A,B,C]]
print(Root)
三 运行结果
['Root', [['A', [['D', []], ['E', [['G', []], ['H', []], ['I', []], ['K', []]]]]], ['B', []], ['C', [['F', []]]]]]
上一篇: ts和vscode设置中文错误提示
下一篇: 多字节字符序列无效