Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Remove and return an element of an expression
ResourceFunction["Pop"][x] deletes the last element in the value of x, returns it and resets x to the result. | |
ResourceFunction["Pop"][x,n] pops the element at position n from x. If n is negative, the position is counted from the end. | |
ResourceFunction["Pop"][x,{i,j,…}] pops the part at position {i,j,…}. | |
ResourceFunction["Pop"][x,{{i1,j1,…},{i2,j2,…}}] pops parts at several positions. |
Assign x to a List:
In[1]:= | ![]() |
Out[1]= | ![]() |
Pop the last element of the list:
In[2]:= | ![]() |
Out[2]= | ![]() |
The value assigned to x has changed:
In[3]:= | ![]() |
Out[3]= | ![]() |
Pop the element at position 3:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
Pop at position 2 from the end:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Pop at positions 1 and 3:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Pop from a 2D array:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
In[12]:= | ![]() |
Out[12]= | ![]() |
Pop from an Association:
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
In[17]:= | ![]() |
Out[17]= | ![]() |
Pop works on sparse arrays:
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
In[20]:= | ![]() |
Out[20]= | ![]() |
Popping the head of a whole expression makes the head be Sequence:
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
In[23]:= | ![]() |
Out[23]= | ![]() |
Popping at an empty list of positions does not change the value:
In[24]:= | ![]() |
Out[24]= | ![]() |
In[25]:= | ![]() |
Out[25]= | ![]() |
In[26]:= | ![]() |
Out[26]= | ![]() |
Popping at position {} pops the whole expression:
In[27]:= | ![]() |
Out[27]= | ![]() |
In[28]:= | ![]() |
Out[28]= | ![]() |
In[29]:= | ![]() |
Out[29]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License