Function Repository Resource:

PositionsByFirstAppearance

Source Notebook

Replace elements with their position of first appearance when flattened

Contributed by: Ed Pegg Jr

ResourceFunction["PositionsByFirstAppearance"][list]

replaces elements of list by their position of first appearence in the flattened list.

Details and Options

The standard ordering of any list starts with 1, with each unique item thereafter corresponding to the next unused integer label in the result.
The result follows the "standard order" described in the OEIS.

Examples

Basic Examples (3) 

Put digits of π into standard order:

In[1]:=
{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2} // ResourceFunction["PositionsByFirstAppearance"]
Out[1]=

Put edges of the Petersen graph into standard order:

In[2]:=
ResourceFunction["PositionsByFirstAppearance"][
 List @@@ GraphData["PetersenGraph", "EdgeList"]]
Out[2]=

Append {1,2,3} to permutations of {1,2,3} and put into standard order:

In[3]:=
ResourceFunction["PositionsByFirstAppearance"][Join[#, {1, 2, 3}]] & /@
  Permutations[{1, 2, 3}]
Out[3]=

Scope (1) 

Put characters of text into standard order:

In[4]:=
ResourceFunction["PositionsByFirstAppearance"][
 Characters["Puts characters of text into standard order:"]]
Out[4]=

Version History

  • 1.0.0 – 03 January 2020

License Information