diff options
Diffstat (limited to 'examples/general/custom_search.py')
-rw-r--r-- | examples/general/custom_search.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/examples/general/custom_search.py b/examples/general/custom_search.py index 0c0b339..905bb2e 100644 --- a/examples/general/custom_search.py +++ b/examples/general/custom_search.py @@ -10,9 +10,9 @@ def conditional_function(node): # method in the filter function. This will iterate over all nodes to # assess if they meet our custom conditions and will return a list of # matches. -matches = filter(conditional_function, t.traverse()) -print len(matches), "nodes have distance >0.3" +matches = list(filter(conditional_function, t.traverse())) +print(len(matches), "nodes have distance >0.3") # depending on the complexity of your conditions you can do the same # in just one line with the help of lambda functions: -matches = filter(lambda n: n.dist>0.3 and n.is_leaf(), t.traverse() ) -print len(matches), "nodes have distance >0.3 and are leaves" +matches = [n for n in t.traverse() if n.dist>0.3 and n.is_leaf()] +print(len(matches), "nodes have distance >0.3 and are leaves") |