项目:
基于Pymysql的专家随机抽取系统
引入库函数:
> import treelib > from treelib import Tree, Node
构造节点类:
> class Nodex(object): def __init__(self, num): self.num = num
构造多叉树:(注意节点的第2个属性已标红,它是节点ID,为str类型,不能与其他节点重复,否则构建节点失败)
> tree1 = Tree() > tree1.create_node('Root', 'root', data = Nodex('3')); tree1.create_node('Child1', 'child1', parent = 'root', data =Nodex('4')); tree1.create_node('Child2', 'child2', parent = 'root', data =Nodex('5')); tree1.create_node('Child3', 'child3', parent = 'root', data =Nodex('6'));\
构造结果:
> tree1.show() Root ├── Child1 ├── Child2 └── Child3 > tree1.show(data_property = 'num') 3 ├── 4 ├── 5 └── 6
打印节点信息:(其实节点是以字典的形式存储的)
> tree1.nodes {'root': Node(tag=Root, identifier=root, data=<__main__.Nodex object at 0x000002265C6A9550>), 'child1': Node(tag=Child1, identifier=child1, data=<__main__.Nodex object at 0x000002265C6A9E10>)}
取出child1节点存储的数据:
> tree1.nodes['child1'].data.num '4'
以上这篇Python多叉树的构造及取出节点数据(treelib)的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“Python多叉树的构造及取出节点数据(treelib)的方法”评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍