GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • WOLFRAM
  • Products
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App
  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs
  • Wolfram AI Ecosystem

This view

  • Original page
  • New address

GeezerVison is showing reference.wolfram.com — Position: Find where specified objects appear in an expression—Wolfram Documentation

Position[expr,pattern]

gives a list of the positions at which objects matching pattern appear in expr.

Position[expr,pattern,levelspec]

finds only objects that appear on levels specified by levelspec.

Position[expr,pattern,levelspec,n]

gives the positions of the first n objects found.

Position[pattern]

represents an operator form of Position that can be applied to an expression.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
Heads  
Properties & Relations  
Possible Issues  
See Also
Tech Notes
Related Guides
Related Links
History
Cite this Page

Position

Position[expr,pattern]

gives a list of the positions at which objects matching pattern appear in expr.

Position[expr,pattern,levelspec]

finds only objects that appear on levels specified by levelspec.

Position[expr,pattern,levelspec,n]

gives the positions of the first n objects found.

Position[pattern]

represents an operator form of Position that can be applied to an expression.

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:
  • nlevels 1 through n
    Infinitylevels 1 through Infinity
    {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 all

Basic Examples  (3)

Find the positions at which b occurs:

Wolfram Language code: Position[{a, b, a, a, b, c, b}, b]
Wolfram Language code: Position[{{a, a, b}, {b, a, a}, {a, b, a}}, b]

Find all positions at which x to any power appears:

Wolfram Language code: Position[{1 + x ^ 2, 5, x ^ 4, a + (1 + x ^ 2) ^ 2}, x ^ _]

Find only those down to level 2:

Wolfram Language code: Position[{1 + x ^ 2, 5, x ^ 4, a + (1 + x ^ 2) ^ 2}, x ^ _, 2]

Find positions with prime values in an association:

Wolfram Language code: Position[<|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, _Integer ? PrimeQ]

Scope  (5)

Find the positions of the first 2 b's that appear on level 1:

Wolfram Language code: Position[{a, b, a, a, b, c, b, a, b}, b, 1, 2]

Use a position operator:

Wolfram Language code: op = Position[_Integer]
Wolfram Language code: op[{1, 1, f[a], 2, 3, y, f[8], 9, f[10]}]

Get the positions of entries in a matrix that are symbols:

Wolfram Language code: Position[{{a, 2}, {3, d}}, _Symbol, {2}, Heads -> False]

Without HeadsFalse, the positions of the head List in each row would also be returned:

Wolfram Language code: Position[{{a, 2}, {3, d}}, _Symbol, {2}]
Wolfram Language code: Extract[{{a, 2}, {3, d}}, %]

Find positions inside an Association:

Wolfram Language code: Position[<|{1 -> 1 + x ^ 2, 2 -> <|"a" -> x ^ 2|>, 3 -> x ^ 4, 4 -> a + (1 + x ^ 2) ^ 2}|>, x ^ _]

Position works with any head:

Wolfram Language code: Position[f[a, b, b, a], b]

Options  (1)

Heads  (1)

By default, Position will search expression heads:

Wolfram Language code: Position[x ^ 2 + y ^ 2, Power]

Use the option Heads->False to exclude them:

Wolfram Language code: Position[x ^ 2 + y ^ 2, Power, Heads -> False]

Properties & Relations  (6)

Use Extract to extract parts based on results from Position:

Wolfram Language code: u = {1 + x^2, 5, x^4, a + (1 + x^2)^2};
Wolfram Language code: Position[u, x ^ _]
Wolfram Language code: Extract[u, %]

Position[expr,expr] returns {{}}, a list containing position {}, that means the whole expression:

Wolfram Language code: Position[x, x]

This returns an empty list of positions, because y was found nowhere in x:

Wolfram Language code: Position[x, y]

Depth-first traversal gives longer lists of indices first:

Wolfram Language code: Position[f[g[h[x]]], _, Infinity]

The keys of an association are not matched by Position:

Wolfram Language code: Position[<|"a" -> {1, b}|>, "a"]

However, keys are used to return positions inside of associations:

Wolfram Language code: Position[<|"a" -> {1, b}|>, _]

Position[p][e] is equivalent to Position[e,p]:

Wolfram Language code: Position[_][{a, b}] === Position[{a, b}, _]

Count returns the length of the result given by Position:

Wolfram Language code: Length[Position[{1, "f", g, "h", "7"}, _ ? StringQ]]
Wolfram Language code: Count[{1, "f", g, "h", "7"}, _ ? StringQ]

Possible Issues  (1)

Position looks for matches based on patterns, which may not be the same as numerical equality:

Wolfram Language code: Position[Range[-1, 1, 0.05], 0.1]

Write a pattern using Condition to force searching based on numerical equality:

Wolfram Language code: Position[Range[-1, 1, 0.05], n_ /; n == 0.1]

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

Tech Notes

    ▪
  • Testing and Searching List Elements
  • ▪
  • Levels in Expressions
  • ▪
  • Applying Functions to Parts of Expressions
  • ▪
  • Finding Expressions That Match a Pattern

Related Guides

    ▪
  • Pattern Matching Functions
  • ▪
  • Elements of Lists
  • ▪
  • Parts of Matrices
  • ▪
  • Parts of Expressions
  • ▪
  • Discrete & Integer Data
  • ▪
  • Expressions
  • ▪
  • Rules & Patterns
  • ▪
  • Handling Arrays of Data
  • ▪
  • List Manipulation
  • ▪
  • Language Overview
  • ▪
  • Functional Programming
  • ▪
  • Function Composition & Operator Forms

Related Links

  • An Elementary Introduction to the Wolfram Language : Parts of Lists
  • NKS|Online  (A New Kind of Science)

History

Introduced in 1988 (1.0) | Updated in 2014 (10.0)

Wolfram Research (1988), Position, Wolfram Language function, https://reference.wolfram.com/language/ref/Position.html (updated 2014).

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_2026_position, author="Wolfram Research", title="{Position}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/Position.html}", note=[Accessed: 12-November-2026]}

BibLaTeX

@online{reference.wolfram_2026_position, organization={Wolfram Research}, title={Position}, year={2014}, url={https://reference.wolfram.com/language/ref/Position.html}, note=[Accessed: 12-November-2026]}

Top
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.