This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Position

Position
gives a list of the positions at which objects matching pattern appear in expr.
Position
finds only objects that appear on levels specified by levelspec.
Position
gives the positions of the first n objects found.
  • Position tests all the subparts of expr in turn to try and find ones that match pattern.
  • A part specification returned by Position represents the whole of expr.
  • Position[list, pattern, {1}, Heads->False] finds positions only of objects that appear as complete elements of list.
  • Position uses standard level specifications:
nlevels through n
Infinitylevels through Infinity
{n}level n only
{n1,n2}levels through
  • A positive level n consists of all parts of expr specified by n indices.
  • A negative level -n consists of all parts of expr with depth n.
  • Level corresponds to the whole expression.
  • With the default option setting Heads->True, Position includes heads of expressions, and their parts.
  • Position traverses expressions in depth-first order, yielding lists of indices in lexicographic order.
Find the positions at which occurs:
Find all positions at which to any power appears:
Find only those down to level 2:
Find the positions at which occurs:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
Find all positions at which to any power appears:
In[1]:=
Click for copyable input
Out[1]=
Find only those down to level 2:
In[2]:=
Click for copyable input
Out[2]=
Find the positions of the first 2 's that appear on level 1:
Depth-first traversal gives longer lists of indices first:
Position works with any head, not just List:
Use Extract to extract parts based on results from Position:
New in 1