Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find positions and values within an expression matching a pattern
ResourceFunction["PositionedCases"][expr,pattern] gives an Association mapping positions of objects in expr matching pattern to their values. | |
ResourceFunction["PositionedCases"][expr,pattern,levelspec] finds only positions and values that appear on the levels specified by levelspec. | |
ResourceFunction["PositionedCases"][expr,pattern,levelspec,n] gives the positions and values of the first n objects found. | |
ResourceFunction["PositionedCases"][pattern] represents an operator form. |
Get positions of integers in an expression along with the integer values:
In[1]:= | ![]() |
Out[1]= | ![]() |
Find values in an Association:
In[2]:= | ![]() |
Out[2]= | ![]() |
Create an operator:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use it:
In[4]:= | ![]() |
Out[4]= | ![]() |
Use a pattern test and a level spec:
In[5]:= | ![]() |
Out[5]= | ![]() |
Also limit the number of results:
In[6]:= | ![]() |
Out[6]= | ![]() |
Up to the first two levels:
In[7]:= | ![]() |
Out[7]= | ![]() |
Use the Heads option to control whether to include heads of expressions:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Retrieve a dataset:
In[10]:= | ![]() |
Out[10]= | ![]() |
Find positions and values in given range:
In[11]:= | ![]() |
Out[11]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License