Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the elements that appear before and after a given value in a list
ResourceFunction["PreviousNextElement"][element,{e1,e2,…}] returns the elements that appear before and after element in {e1,e2,…}. |
Find previous/next elements in a list of integers:
In[1]:= | ![]() |
Out[1]= | ![]() |
Find previous/next elements in a list of strings:
In[2]:= | ![]() |
Out[2]= | ![]() |
Elements do not have to be numbers or strings:
In[3]:= | ![]() |
Out[3]= | ![]() |
If the element doesn't exist, Missing["NotFound"] is returned:
In[4]:= | ![]() |
Out[4]= | ![]() |
By default, searches will not wrap around the list:
In[5]:= | ![]() |
Out[5]= | ![]() |
With the option setting WrapAround→True, searches will wrap around the list:
In[6]:= | ![]() |
Out[6]= | ![]() |
If elements within the list are not unique, the first match is returned:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Matches are found after evaluation:
In[9]:= | ![]() |
Out[9]= | ![]() |
Which two U.S. states is Illinois between alphabetically:
In[10]:= | ![]() |
Out[10]= | ![]() |
Between which two planets is the Earth when listed in order of increasing radius:
In[11]:= | ![]() |
Out[11]= | ![]() |
In[12]:= | ![]() |
Out[12]= | ![]() |
Find phrases within text:
In[13]:= | ![]() |
In[14]:= | ![]() |
Out[15]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License