Function Repository Resource:

DropSmallest

Source Notebook

Drop the smallest values from a list

Contributed by: Sander Huisman

ResourceFunction["DropSmallest"][list,n]

drops the smallest n numbers from list.

ResourceFunction["DropSmallest"][n]

represents the operator form of ResourceFunction["DropSmallest"].

Examples

Basic Examples (2) 

Drops the smallest two values:

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

Use the operator form, by first creating an operator op:

In[2]:=
op = ResourceFunction["DropSmallest"][2]
Out[2]=

Apply the operator:

In[3]:=
op[{6, 5, 3, 8, 4, 2, 9}]
Out[3]=

Scope (2) 

With n=0, nothing is deleted:

In[4]:=
ResourceFunction["DropSmallest"][{6, 5, 3, 8, 4, 2, 9}, 0]
Out[4]=

A negative number deletes the largest n numbers:

In[5]:=
ResourceFunction["DropSmallest"][{6, 5, 3, 8, 4, 2, 9}, -2]
Out[5]=

Properties and Relations (2) 

If n is larger than the length of the list then an empty list is returned:

In[6]:=
ResourceFunction["DropSmallest"][{6, 5, 3, 8, 4, 2, 9}, 12]
Out[6]=

DropSmallest is complementary to TakeSmallest:

In[7]:=
in = {6, 5, 3, 8, 4, 2, 9};
In[8]:=
TakeSmallest[in, 2]
Out[8]=
In[9]:=
ResourceFunction["DropSmallest"][in, 2]
Out[9]=

Publisher

SHuisman

Version History

  • 1.0.0 – 02 April 2020

Related Resources

License Information