Wolfram: List. Position (Get Positions of Elements by Pattern)
Index of a Element
Index is an integer, that indicates the nth element.
For example, if we have
{a, {{b,c}, d}, e}
- index
1isa - index
2is{{b,c}, d} - index
3ise
Index counting start at 1. Index 0 means the Head of Expression.
Position of a Subexpression
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
Get Position of a Element
Position[expr, pattern]-
Return a list of positions that Pattern occur in expression. If no exist, return a empty list.
Position[expr, pattern, levelSpec]→ limit to Level Spec.Position[expr, pattern, levelSpec, n]→ return first n.
(* position of e is {3} *) Position[ {a,{{b,c},a},e}, e ] (* {{3}} *) (* position of a is {1} and {2, 2} *) Position[ {a,{{b,c},a},e}, a ] (* {{1}, {2, 2}} *) (* when not found, empty list *) Position[ {a,{{b,c},a},e}, m ] (* {} *) (* position of b *) Position[ {a,{{b,c},a},e}, b ] (* {{2, 1, 1}} *) (* position of {b, c} *) Position[ {a,{{b,c},a},e}, {b, c} ] (* {{2, 1}} *) Example. Limit Depth Level
(* find 7, only in level 1 *) Position[ {7, {{2, 7}, 2}, 7}, 7, {1} ] (* {{1}, {3}} *) (* find 7, only in level 2 *) Position[ {7, {{2, 7}, 2}, 7}, 7, {2} ] (* {} *) (* find 7, only in level 3 *) Position[ {7, {{2, 7}, 2}, 7}, 7, {3} ] (* {{2, 1, 2}} *) (* find 7, in all levels *) Position[ {7, {{2, 7}, 2}, 7}, 7, {1, Infinity} ] (* {{1}, {2, 1, 2}, {3}} *)
Get Element by Position
Wolfram. List Concepts
Wolfram. List Operations, and Loop, Iteration, Recursion
- Wolfram: List Operations
- Wolfram: List. Table (Create List, Nested Array)
- Wolfram: Range (Create Flat List)
- Wolfram: List. Get Element by Index (Part, Take, Drop, First, Last, Most, Rest)
- Wolfram: Extract (Get Element by Position)
- Wolfram: List. Add Element
- Wolfram: List. Delete Element
- Wolfram: List. Change Element
- Wolfram: List. Check Exist, Count
- Wolfram: List. Position (Get Positions of Elements by Pattern)
- Wolfram: List. Join, Union, Intersection, Difference
- Wolfram: List. Min, Max
- Wolfram: List. Select (Filter)
- Wolfram: List. Sort Reverse Ordering
- Wolfram: Flatten
- Wolfram: Riffle (Add at Every Nth)
- Wolfram: RotateLeft
- Wolfram: Padding
- Wolfram: List. Partition, Reshape, Split, Gather
- Wolfram: Transpose
- Wolfram: List. Same Items Counts, Tally, Group
- Wolfram: List. Combinatorics
- Wolfram: Iteration
- Wolfram: Map Function to List
- Wolfram: Scan (foreach)
- Wolfram: Nest, FixedPoint (Recursion)
- Wolfram: Fold (reduce)
- Wolfram: Loop