TreeDelete
TreeDelete[tree,pos]
deletes the subtree of tree at the position specified by pos.
TreeDelete[tree,{pos1,pos2,…}]
deletes subtrees at several positions.
TreeDelete[pos]
represents an operator form of TreeDelete that can be applied to a tree.
Details and Options
- TreeDelete allows removal of subtrees at any position in a Tree object.
- TreeDelete[tree,{i,j,…}] deletes the subtree at position {i,j,…}.
- TreeDelete can use the position specifications returned by TreePosition as well as extended forms as used in functions such as TreeExtract and TreeReplacePart. »
- An individual position specification pos can be given as {part1,part2,…}, where part specifications parti include:
-
i the i child -i the i child from the end {i1,i2,…} the list of children with part numbers i1, i2, … "key" the child whose key is "key" Key[k] the child with an arbitrary key k - In TreeDelete[tree,{p1,p2,…}], {p1,p2,…} is interpreted as a list of individual position specifications if all the pi are lists. Otherwise, {p1,p2,…} will be taken to be an individual position specification. »
- TreeDelete works on trees containing an Association of subtrees, using the same specification for keys as in Part. »
- TreeDelete[pos][tree] is equivalent to TreeDelete[tree,pos].
- TreeDelete has the same options as Tree.
Examples
open allclose allBasic Examples (3)
Delete the second child of a tree:
Delete a subtree at any position:
Delete subtrees at several positions:
Use the operator form of TreeDelete:
Scope (5)
Associations (5)
Delete a subtree of a tree containing an association by key:
If the key is a string, the Key wrapper is optional:
Delete a subtree of a tree containing an association by key:
Delete a subtree of a tree containing an association by position:
Delete several subtrees of a tree containing an association:
Delete a nested subtree of a tree containing an association:
Delete several nested subtrees of a tree containing an association:
Properties & Relations (7)
Subtrees can be deleted, as well as inserted or replaced:
Construct a tree from the heads in an expression:
TreeDelete deletes a subtree of a tree:
This corresponds to deleting a subexpression of an expression:
Delete can delete subexpressions directly:
If pos is not a list, pos and {pos} are equivalent specifications:
Deleting position {} deletes the whole tree:
TreeDelete ignores repeated positions:
TreeDelete can use the lists of positions returned by TreePosition:
These are the subtrees returned by TreeExtract:
TreeDelete[tree,{p1,p2,…}] treats {p1,p2,…} as a list of individual position specifications if all the pi are lists:
For {{1,2},{3,4}}, the subtrees at positions {1,2} and {3,4} are deleted:
If any pi is not a list, {p1,p2,…} is treated as a list of part specifications:
For {{{1,2},{3,4}}}, parts 3 and 4 of parts 1 and 2 are deleted:
Possible Issues (1)
TreeDelete[tree,{}] does not delete any subtrees because the list of positions is empty:
TreeDelete[tree,{{}}] deletes position {}, which corresponds to the whole tree:
Text
Wolfram Research (2021), TreeDelete, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeDelete.html (updated 2024).
CMS
Wolfram Language. 2021. "TreeDelete." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/TreeDelete.html.
APA
Wolfram Language. (2021). TreeDelete. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeDelete.html