diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-23 09:20:52 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-23 09:20:52 -0400 |
commit | 2d381449ece1326b25c5fbbbf3ee7987f03d1ee2 (patch) | |
tree | e513ccfac017d19ec0179b45e5cd4b16fa986301 | |
parent | 8fd151cc1d4efad33341283c6509e28d8f139f50 (diff) | |
download | bugseverywhere-2d381449ece1326b25c5fbbbf3ee7987f03d1ee2.tar.gz |
libbe/tree.Tree.traverse(depthFirst)->depth_first & stripped trailing spaces.
-rw-r--r-- | libbe/tree.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libbe/tree.py b/libbe/tree.py index fe791a5..0256407 100644 --- a/libbe/tree.py +++ b/libbe/tree.py @@ -35,7 +35,7 @@ class Tree(list): >>> a = Tree(); a.n = "a" >>> a.append(c) >>> a.append(b) - + >>> a.branch_len() 5 >>> a.sort(key=lambda node : -node.branch_len()) @@ -44,7 +44,7 @@ class Tree(list): >>> a.sort(key=lambda node : node.branch_len()) >>> "".join([node.n for node in a.traverse()]) 'abdgcefhi' - >>> "".join([node.n for node in a.traverse(depthFirst=False)]) + >>> "".join([node.n for node in a.traverse(depth_first=False)]) 'abcdefghi' >>> for depth,node in a.thread(): ... print "%*s" % (2*depth+1, node.n) @@ -97,11 +97,11 @@ class Tree(list): for child in self: child.sort(*args, **kwargs) - def traverse(self, depthFirst=True): + def traverse(self, depth_first=True): """ Note: you might want to sort() your tree first. """ - if depthFirst == True: + if depth_first == True: yield self for child in self: for descendant in child.traverse(): @@ -119,7 +119,7 @@ class Tree(list): When flatten==False, the depth of any node is one greater than the depth of its parent. That way the inheritance is explicit, but you can end up with highly indented threads. - + When flatten==True, the depth of any node is only greater than the depth of its parent when there is a branch, and the node is not the last child. This can lead to ancestry ambiguity, @@ -138,8 +138,8 @@ class Tree(list): stack = [] # ancestry of the current node if flatten == True: depthDict = {} - - for node in self.traverse(depthFirst=True): + + for node in self.traverse(depth_first=True): while len(stack) > 0 \ and id(node) not in [id(c) for c in stack[-1]]: stack.pop(-1) |