WolframLang: Position of an Element
Position Spec
A position is a list of integers that uniquely specify a part of expression.
For example, if we have
{a, {{b,c}, d}, e}
- position
{1}
isa
- position
{2}
is{{b,c}, d}
- position
{2,1}
is{b,c}
- position
{2,2}
isd
- position
{2,1,1}
isb
- position
{2,1,2}
isc
- position
{3}
ise
Index counting start at 1. Index 0 means the Head of Expression.
Get Element by Position Spec: Extract
Extract[expr, position]
-
return the part of expr at a given position.
Extract
tree = {a, {{b,c}, d}, e}; Extract[ tree, {1} ] === a Extract[ tree, {2} ] === {{b, c}, d} Extract[ tree, {3} ] === e Extract[ tree, {2, 1} ] === {b, c} Extract[ tree, {2, 1, 1} ] === b