当前位置: 首页>>代码示例>>Python>>正文


Python Tree.path_to_leaf方法代码示例

本文整理汇总了Python中Tree.path_to_leaf方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.path_to_leaf方法的具体用法?Python Tree.path_to_leaf怎么用?Python Tree.path_to_leaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree.path_to_leaf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import Tree [as 别名]
# 或者: from Tree import path_to_leaf [as 别名]
def main():
	branches = list()
	# n1 = Node( 1, 0 ) # the root node
	# n1.add_descendant([ Node( 0, 1 ), Node( 2, 2 )])
	b1 = Branch( Node( 1, 0 ), Node( 0, 1 ), Node( 2, 2 ))
	branches.append( b1 )
	
	t = Tree()
	t.graft_branch( b1 )
	# t.graft( branches[n1.identify()] )
	
	
	print t
	print
	
	for tn in t.leaves:
		print tn, tn.parent, tn.parent.parent
	
	print
	
	for leaf in t.leaves:
		print leaf, t.path_to_leaf( leaf )
	
	print
	# n2 = Node( 0, 1 )
	# n2.add_descendant([ Node( 2, 2 ), Node( 1, 4 ) ])
	b2 = Branch( Node( 0, 1 ), Node( 2, 2 ), Node( 1, 4 ))
	branches.append( b2 )
	t.graft_branch( b2 )
	
	# t.graft( branches[n2.identify()] )
	
	print t
	print
	
	for tn in t.leaves:
		print tn, tn.parent, tn.parent.parent
	
	print
	
	for leaf in t.leaves:
		print leaf, t.path_to_leaf( leaf )
	print
	
	# n3 = Node( 2, 2 )
	# n3.add_descendant([ Node( 1, 4 ), Node( 0, 5 )])
	# t.graft( n3 )
	print "begin here:"
	b3 = Branch( Node( 2, 2 ), Node( 1, 4 ), Node( 0, 5 ))
	branches.append( b3 )
	t.graft_branch( b3 )
	print "end here:"
	
	print t
	print
	
	for tn in t.leaves:
		print tn, tn.parent, tn.parent.parent
	
	print
	
	for leaf in t.leaves:
		print leaf, t.path_to_leaf( leaf )
		
	# sys.exit()
	
	
	# n4 = Node( 1, 4 )
	# n4.add_descendant([ Node( 0, 5 ), Node( 2, -1 )])
	# t.graft( n4 )
	b4 = Branch( Node( 1, 4 ), Node( 0, 5 ), Node( 2, -1 ))
	branches.append( b4 )
	t.graft_branch( b4 )
	
	print t
	print

	# n5 = Node( 0, 5 )
	# n5.add_descendant([ Node( 1, 6 ), Node( 2, -1 )])
	# t.graft( n5 )
	b5 = Branch( Node( 0, 5 ), Node( 1, 6 ), Node( 2, -1 ))
	branches.append( b5 )
	t.graft_branch( b5 )
	
	
	print t
	print
	
	# n6 = Node( 1, 6 )
	# n6.add_descendant([ Node( 0, -1 ), Node( 2, -1 )])
	# t.graft( n6 )
	b6 = Branch( Node( 1, 6 ), Node( 0, -1 ), Node( 2, -1 ))
	branches.append( b6 )
	t.graft_branch( b6 )
	
	print t
	print
	
	for tn in t.leaves:
		print tn, tn.parent, tn.parent.parent, tn.parent.parent.parent, tn.parent.parent.parent.parent
#.........这里部分代码省略.........
开发者ID:polarise,项目名称:BioClasses,代码行数:103,代码来源:test_Tree.py


注:本文中的Tree.path_to_leaf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。