pymel.util.trees.treeFromIsChild

treeFromIsChild(isChildFn, *elements)
This function will build a tree from the provided sequence and a comparison function in the form:
isChildFn(c,p): returns True if c is a child of p (direct or indirect), False otherwise
The comparison function must satisfy the following conditions for all a, b, and c in the tree:
isChildFn(a,a) == False
(an object is not a child of itself)
if isChildFn(a,b) AND isChildFn(b,c), then isChildFn(a,c)
(indirect children are inherited)
if isChildFn(a,b) AND isChildFn(a,c), then isChildFn(b,c) OR isChildFn(c,b) OR b==c
(if a child has two distinct parents, then one must be the parent of the other)

If any member of elements is itself a Tree, then it will be treated as a subtree (or subtrees, in the case of a forest) to be merged into the returned tree structure; for every root in such a subtree, the structure below the root will be unaltered, though the entire subtree itself may be parented to some other member of elements.

>>> lst = ['aab', 'aba', 'aa', 'ba', 'bbb', 'a', 'b', 'bb', 'ab', 'bab', 'bba']
>>> def isChild(s1, s2) :
...     return s1.startswith(s2) 
>>> a = treeFromIsChild (isChild, *lst)
>>> a.sort()
>>> print a.formatted()
+: a
|-+: aa
| \--: aab
\-+: ab
  \--: aba
<BLANKLINE>
+: b
|-+: ba
| \--: bab
\-+: bb
  |--: bba
  \--: bbb

Previous topic

pymel.util.trees.treeFromDict

Next topic

pymel.util.trees.Callable

Core

Core Modules

Other Modules

This Page