Position
Details and Options
- Position [expr,pattern] tests all the subparts of expr in turn to try and find ones that match pattern.
- Position returns a list of positions in a form suitable for use in Extract , ReplacePart , and MapAt . The form is different from the one used in Part .
- Position looks only for matches to values in Association objects that appear in expr. It returns any part specifications within Association objects in the form Key [k].
- The default level specification for Position is {0,Infinity }, with Heads->True .
- 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:
-
n levels 1 through n{n} level n only{n1,n2} levels n1 through n2
- 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 0 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.
- Position [pattern][expr] is equivalent to Position [expr,pattern].
Examples
open all close allBasic Examples (4)
Find the positions at which b occurs:
Find all positions at which x to any power appears:
Find only those down to level 2:
Find positions in an Association :
Find positions with prime values:
Scope (2)
Find the positions of the first 2 b's that appear on level 1:
Depth-first traversal gives longer lists of indices first:
Options (1)
Properties & Relations (2)
See Also
FirstPosition Cases Count SequencePosition StringPosition PositionLargest PositionSmallest PositionIndex LengthWhile Ordering SparseArray ReplaceList Insert Delete ArrayRules Extract
Function Repository: PositionedCases SelectPositions PositionQ SubexpressionPositions ToExplicitPosition SelectIndices
History
Introduced in 1988 (1.0) | Updated in 2014 (10.0)
Text
Wolfram Research (1988), Position, Wolfram Language function, https://reference.wolfram.com/language/ref/Position.html (updated 2014).
CMS
Wolfram Language. 1988. "Position." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/Position.html.
APA
Wolfram Language. (1988). Position. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Position.html
BibTeX
@misc{reference.wolfram_2025_position, author="Wolfram Research", title="{Position}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/Position.html}", note=[Accessed: 04-January-2026]}
BibLaTeX
@online{reference.wolfram_2025_position, organization={Wolfram Research}, title={Position}, year={2014}, url={https://reference.wolfram.com/language/ref/Position.html}, note=[Accessed: 04-January-2026]}