本文整理汇总了Python中tree.Tree.subtrees方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.subtrees方法的具体用法?Python Tree.subtrees怎么用?Python Tree.subtrees使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.subtrees方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: size
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
if T.root is EmptyValue:
return 0
else:
count = 1
for tree in T.subtrees:
count += size(tree)
return count
a = Tree(1)
b = Tree(2)
c = Tree(3)
d = Tree(4)
e = Tree(5)
f = Tree(6)
g = Tree(7)
h = Tree(8)
g.subtrees= [h]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]
print(depth_greater(a,2))
示例2: internal_nodes
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
__author__ = 'Udara'
from tree import Tree,EmptyValue
def internal_nodes(T):
if T.root is EmptyValue:
return 0
#can't use T.subtrees is [] here.
#can't use T.subtrees is [] here.
elif T.subtrees == []:
return 0
else:
count = 1
for trees in T.subtrees:
count += internal_nodes(trees)
return count
a = Tree(1)
b = Tree(2)
c = Tree(3)
d = Tree(4)
e = Tree(5)
b.subtrees = [d,e]
a.subtrees = [b,c]
print(internal_nodes(a))
示例3: count_dups1
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
return count
else:
seen.append(T.root)
count = 0
for tree in T.subtrees:
count += count_dups1(tree,seen)
return count
a = Tree(1)
b = Tree(2)
c = Tree(3)
d = Tree(4)
e = Tree(5)
f = Tree(6)
g = Tree(7)
h = Tree(8)
i = Tree(8)
g.subtrees= [h,i]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]
print(count_dups(a))#1
print(count_dups(b))#0
示例4: count_even
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
for tree in T.subtrees:
count += count_even(tree)
return count
else:
count = 0
for tree in T.subtrees:
count += count_even(tree)
return count
a = Tree(1)
b = Tree(2)
c = Tree(3)
d = Tree(4)
e = Tree(5)
f = Tree(6)
g = Tree(7)
h = Tree(8)
i = Tree(8)
g.subtrees= [h,i]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]
print(count_even(a))#5
print(count_even(b))#2
示例5: depth
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
assumes proper D that isn't too big or anything
"""
if d == 0:
return 1
else:
count= 0
for trees in T.subtrees:
count += depth(T,d-1)
return count
a = Tree(1)
b = Tree(2)
c = Tree(3)
d = Tree(4)
e = Tree(5)
f = Tree(6)
g = Tree(7)
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]
print(depth(a,1))#2
print(depth(a,2))#4
示例6: test_has_extra_not_equal
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
def test_has_extra_not_equal(self):
tree2 = Tree(1)
tree2.subtrees = [Tree('Hi'), Tree(3)]
tree2.subtrees[0].subtrees = [Tree(2)]
self.assertFalse(self.tree == tree2)
示例7: test_missing_item_not_equal
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
def test_missing_item_not_equal(self):
tree2 = Tree(1)
tree2.subtrees = [Tree(3)]
self.assertFalse(self.tree == tree2)
示例8: test_order_matters
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
def test_order_matters(self):
tree2 = Tree(1)
tree2.subtrees = [Tree(3), Tree('Hi')]
self.assertFalse(self.tree == tree2)
示例9: test_simple_eq
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
def test_simple_eq(self):
tree2 = Tree(1)
tree2.subtrees = [Tree('Hi'), Tree(3)]
self.assertTrue(self.tree == tree2)