def prettyPrint(trees): i=0 for t in trees: i += 1 print ("Tree:", i) TreeModule.printTreeIndented(t) print
def prettyPrint(trees): i = 0 for t in trees: i += 1 print("Tree:", i) TreeModule.printTreeIndented(t) print
import TreeModule # Create some trees using the function in TreeModule t1 = TreeModule.treeFactory("ABCDEFGHIJKLMNOPQRSTUVWXYZ") t2 = TreeModule.treeFactory(("1","2","3","4","5","6","7","8","9","10","11")) # pretty print a collection of trees def prettyPrint(trees): i=0 for t in trees: i += 1 print ("Tree:", i) TreeModule.printTreeIndented(t) print # To test functions in this module (from the edit window): # select the "Run" pull down menu, thne choose "Run Module" # Note: TreeModule will be imported. You can access its definition # by prefixing functions and class name with "TreeModule", i.e. # >>> tr= TreeModule.treeFactory([1,2,3,4]) # >>> tr # 3 2 1 4 # >>> tr2 = treeFactory([4,5,6,7]) # Traceback (most recent call last): # File "<pyshell#4>", line 1, in -toplevel- # tr2 = treeFactory([4,5,6,7]) # NameError: name 'treeFactory' is not defined
import TreeModule # Create some trees using the function in TreeModule t1 = TreeModule.tree_factory("ABCDEFGHIJKLMNOPQRSTUVWXYZ") t2 = TreeModule.tree_factory( ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")) # pretty print a collection of trees def prettyPrint(trees): i = 0 for t in trees: i += 1 print("Tree:", i) TreeModule.print_tree_indented(t) print # To test functions in this module (from the edit window): # select the "Run" pull down menu, thne choose "Run Module" # Note: TreeModule will be imported. You can access its definition # by prefixing functions and class name with "TreeModule", i.e. # >>> tr= TreeModule.tree_factory([1,2,3,4]) # >>> tr # 3 2 1 4 # >>> tr2 = tree_factory([4,5,6,7]) # Traceback (most recent call last): # File "<pyshell#4>", line 1, in -toplevel- # tr2 = tree_factory([4,5,6,7])
import TreeModule # Create some trees using the function in TreeModule t1 = TreeModule.treeFactory("ABCDEFGHIJKLMNOPQRSTUVWXYZ") t2 = TreeModule.treeFactory(("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")) # pretty print a collection of trees def prettyPrint(trees): i = 0 for t in trees: i += 1 print("Tree:", i) TreeModule.printTreeIndented(t) print # To test functions in this module (from the edit window): # select the "Run" pull down menu, thne choose "Run Module" # Note: TreeModule will be imported. You can access its definition # by prefixing functions and class name with "TreeModule", i.e. # >>> tr= TreeModule.treeFactory([1,2,3,4]) # >>> tr # 3 2 1 4 # >>> tr2 = treeFactory([4,5,6,7]) # Traceback (most recent call last): # File "<pyshell#4>", line 1, in -toplevel- # tr2 = treeFactory([4,5,6,7]) # NameError: name 'treeFactory' is not defined
def treeGenerator(s, n): if not n: yield None for i in range(n): for left in treeGenerator(s + 1, i): for right in treeGenerator(s + 1, n - 1 - i): yield TreeModule.Tree(s, left, right)