map_leaf method for tree
This commit is contained in:
parent
813c1f096e
commit
e64613f5be
@ -194,15 +194,27 @@ class Tree(object):
|
||||
... ("*", (3, 4)),
|
||||
... 2))
|
||||
>>> t = Tree.from_nested_parenthesis(nested_par)
|
||||
>>> print(t)
|
||||
+
|
||||
> *
|
||||
| > 3
|
||||
| > 4
|
||||
> 2
|
||||
>>> print(t.map_leaf(lambda x:2*x))
|
||||
+
|
||||
> *
|
||||
| > 6
|
||||
| > 8
|
||||
> 4
|
||||
|
||||
"""
|
||||
try:
|
||||
left_applied = self.left_value.apply(function)
|
||||
left_applied = self.left_value.map_leaf(function)
|
||||
except AttributeError:
|
||||
left_applied = function(self.left_value)
|
||||
|
||||
try:
|
||||
right_applied = self.right_value.apply(function)
|
||||
right_applied = self.right_value.map_leaf(function)
|
||||
except AttributeError:
|
||||
right_applied = function(self.right_value)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user