Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Pairs each element of a list with its index
ResourceFunction["AddIndices"][{e1,e2,…}] pairs each ei with its index i forming the list {{1,e1},{2,e2},…}. | |
ResourceFunction["AddIndices"][{e1,e2,…},imin] pairs each ei with its index starting from imin forming the list {{imin,e1},{imin+1,e2},…}. | |
ResourceFunction["AddIndices"][{e1,e2,…},imin,di] uses step di forming the list {{imin,e1},{imin+di,e2},…}. |
Start with the index 4:
In[2]:= |
Out[2]= |
The starting index and the step can be symbolic. Start the index at x:
In[3]:= |
Out[3]= |
The step can also be symbolic:
In[4]:= |
Out[4]= |
Use Select to choose palindromic words while retaining their indices:
In[5]:= |
Out[7]= |
Sort the strings and retain their original indices:
In[8]:= |
Out[10]= |
The functionality of AddIndices can be achieved using MapIndexed:
In[11]:= |
Out[11]= |
AddIndices is roughly 4 times faster:
In[12]:= |
Out[13]= |
This work is licensed under a Creative Commons Attribution 4.0 International License