没有类的Python树

2024-04-16 18:58:03 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在不使用python中的类的情况下实现树?我只能使用列表、字典和队列。显然没有库bintree。在


Tags: 列表字典队列情况bintree
2条回答

我通常使用^{}

from collections import defaultdict

def Tree():
    return defaultdict(Tree)

用法:

^{pr2}$

奖励:卡拉斯唱歌O Mio Babbino Caro

你可以用

{'value': None, 'nodes': []} 

表示每个节点。在

例如:

enter image description here

可以表示为:

^{pr2}$

注:仅供教育之用。已经实现了更高效的数据结构。在

相关问题 更多 >