skbio.tree.TreeNode.find_by_func

TreeNode.find_by_func(func)[source]

Find all nodes given a function

This search method is based on the current subtree, not the root.

Parameters:

func : a function

A function that accepts a TreeNode and returns True or Fals, where True indicates the node is to be yielded

Returns:

GeneratorType

A generator that yields nodes

See also

find, find_all, find_by_id

Examples

>>> from six import StringIO
>>> from skbio import TreeNode
>>> tree = TreeNode.read(StringIO("((a,b)c,(d,e)f);"))
>>> func = lambda x: x.parent == tree.find('c')
>>> [n.name for n in tree.find_by_func(func)]
['a', 'b']