【发布时间】:2017-03-06 14:49:31
【问题描述】:
python 3.6 中trees的实现有什么内置方法吗? 如果不是,请用另一种方法解释
【问题讨论】:
标签: python python-3.x tree binary-tree
python 3.6 中trees的实现有什么内置方法吗? 如果不是,请用另一种方法解释
【问题讨论】:
标签: python python-3.x tree binary-tree
这取决于你说的是哪种树。有二叉树库(它确实是一个学习库,但可能有用:
https://pypi.python.org/pypi/binarytree/1.1.1
如果您的树不是二元树,一种选择是只使用字典中的字典:
import collections
def Tree():
return collections.defaultdict(Tree)
在此处阅读有关此方法的更多信息:https://gist.github.com/hrldcpr/2012250
还有treelib:https://github.com/caesar0301/treelib
换句话说,有很多可能的实现,但这取决于你需要什么。如果你可以为你想做的事情添加更多细节,你会得到更好的建议。
【讨论】: