Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Choose positions of an expression by certain traversal-ordering criteria
ResourceFunction["TraversalOrderSelect"][list,scheme] sorts elements from list according to a specified traversal scheme. |
Sort a list of positions in leftmost outermost order:
In[1]:= |
|
Out[1]= |
|
Note that the order of criteria given in the scheme matters for sorting:
In[2]:= |
|
Out[2]= |
|
Return only the first position from the list sorted by rightmost innermost order:
In[3]:= |
|
Out[3]= |
|
Specify that two positions should be taken from the list sorted by innermost rightmost order:
In[4]:= |
|
Out[4]= |
|
If the third element of scheme is greater than the length of list, the fully sorted list is given:
In[5]:= |
|
Out[5]= |
|
Select the third position from the leftmost outermost sorting order:
In[6]:= |
|
Out[6]= |
|
While this function was created to sort a list of lists, it can handle list elements with any arbitrary Head. In this example, the different heads are lexicographically ordered while the parts remain sorted by direction and depth order:
In[7]:= |
|
Out[7]= |
|
In[8]:= |
|
Out[8]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License