# SelectPositions

Contributed by: Richard Hennigan (Wolfram Research)

Equivalent to Select, but returns positions instead of values

 ResourceFunction["SelectPositions"][list,crit] picks out all positions pi of list for which crit[elementi] is True. ResourceFunction["SelectPositions"][list,crit,n] picks out the first n positions for which crit[elementi] is True. ResourceFunction["SelectPositions"][crit] represents an operator form of ResourceFunction["SelectPositions"] that can be applied to an expression.

## Details and Options

The object list can have any head, not necessarily List.
When used on an Association,ResourceFunction["SelectPositions"] picks out positions according to their values.
ResourceFunction["SelectPositions"] can be used on SparseArray objects.
ResourceFunction["SelectPositions"][crit][list] is equivalent to ResourceFunction["SelectPositions"][list,crit].

## Examples

### Basic Examples

Select positions that have even elements:

 In[1]:=
 Out[1]=

Use a pure function to test each element:

 In[2]:=
 Out[2]=

Return only the first position selected:

 In[3]:=
 Out[3]=

Use the operator form of SelectPositions:

 In[4]:=
 Out[4]=

SelectPositions operates on values in an Association:

 In[5]:=
 Out[5]=

### Scope

SelectPositions picks out positions for which applying the criterion explicitly yields True:

 In[6]:=
 Out[6]=

Applying the criterion to the symbolic object x does not explicitly yield :

 In[7]:=
 Out[7]=

Find positions of pairs containing x:

 In[8]:=
 Out[8]=

Find up to 2 pairs containing x:

 In[9]:=
 Out[9]=

Fewer than the requested elements may be returned:

 In[10]:=
 Out[10]=

Use an operator form as selection criterion:

 In[11]:=
 Out[11]=

Use SelectPositions in operator form:

 In[12]:=
 Out[12]=

### Generalizations & Extensions

SelectPositions works with any head, not just List:

 In[13]:=
 Out[13]=

SelectPositions works with SparseArray objects:

 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

### Applications

Get positions of elements that match a criteria for use in other functions:

 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=

Use with Extract:

 In[19]:=
 Out[19]=

Use with ReplacePart:

 In[20]:=
 Out[20]=

Use with MapAt:

 In[21]:=
 Out[21]=

Use with Insert:

 In[22]:=
 Out[22]=

### Properties and Relations

SelectPositions is similar to Position except that it uses a function instead of a pattern:

 In[23]:=
 Out[23]=

Select the position of lists that have sum of elements less than 10:

 In[24]:=
 Out[25]=

Use Position to get the same result:

 In[26]:=
 Out[26]=