Wolfram Research

Function Repository Resource:

DropLargest

Source Notebook

Drop the largest values from a list

Contributed by: Sander Huisman

ResourceFunction["DropLargest"][list,n]

drops the largest n numbers from list.

ResourceFunction["DropLargest"][n]

represents an operator form of ResourceFunction["DropLargest"] that can be applied to an expression.

Examples

Basic Examples

Drop the largest two values:

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

Use the operator form by first creating an operator op:

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

Apply the operator:

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

Scope

When n is 0 nothing is deleted:

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

A negative number deletes the smallest n numbers:

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

Properties and Relations

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

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

DropLargest is complementary with TakeLargest:

In[7]:=
in = {1, 5, 3, 8, 4, 2, 9};
In[8]:=
ResourceFunction["DropLargest"][in, 2]
Out[8]=
In[9]:=
TakeLargest[in, 2]
Out[9]=

Resource History

Related Resources

License Information