WOLFRAM

TakeLargest[data,n]

gives the n largest elements of data, sorted in descending order.

TakeLargest[dataprop,n]

gives the property prop for the n largest elements in data.

TakeLargest[data,n,p]

uses the ordering function p for sorting.

represents an operator form of TakeLargest that can be applied to an expression.

Details and Options

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Take the two largest numbers in a list:

Out[1]=1

Do the same using the operator form of TakeLargest:

Out[2]=2
Out[3]=3

Get the three largest quantities in a list of Quantity objects:

Out[1]=1

Quantities can be present in multiple units:

Out[2]=2

Get the two latest dates in a list of DateObject constructs:

Out[1]=1

Take the three largest values in an association:

Out[1]=1

Scope  (9)Survey of the scope of standard use cases

Take the four largest numbers, or as many as are available if fewer:

Out[1]=1

Quantities can be given as QuantityArray:

Out[1]=1
Out[2]=2

By default, Missing[] and several other symbolic expressions are excluded from the results:

Out[1]=1

Get the two largest elements in a list:

Out[2]=2

Get the positions of the two largest elements in a list:

Out[3]=3

Get the two largest elements in a list along with their positions:

Out[4]=4

Get the two largest elements in a list with their positions given first:

Out[5]=5

Get associations containing the element and position of the two largest elements in a list:

Out[6]=6

Find the three largest elements in a TabularColumn object:

Out[1]=1
Out[2]=2
Out[3]=3

Get the four rows with the largest elements in the first column in a Tabular object:

Out[1]=1

Ties in the first column are resolved by comparing values in the second column:

Out[2]=2
Out[3]=3

Take a list of numeric expressions or infinities:

By default, TakeLargest sorts the elements using NumericalOrder:

Out[2]=2
Out[3]=3

Use canonical Order instead:

Out[4]=4
Out[5]=5

Take a list of lists of integers:

They are not numeric elements, so they are sorted by default following canonical order:

Out[2]=2
Out[3]=3

Use instead lexicographic order, which will sort the list by their respective first elements:

Out[4]=4
Out[5]=5

Take a list of complex numbers:

Out[1]=1

Following reverse NumericalOrder, TakeLargest selects numbers with decreasing real part:

Out[2]=2
Out[3]=3

Options  (2)Common values & functionality for each option

ExcludedForms  (2)

By default, Missing[] and several other symbolic expressions are excluded from the results:

Out[1]=1

Specify which elements should be excluded:

Out[2]=2

By default, TakeLargest takes all elements into account when finding the largest ones:

Out[1]=1

Exclude particular elements:

Out[2]=2

Exclude elements matching a given pattern:

Out[3]=3

Applications  (6)Sample problems that can be solved with this function

Get the three planets with the largest radii:

Out[1]=1

Get the release dates of the five most recent James Bond movies:

Out[1]=1

Find the South American countries with the highest life expectancy for their inhabitants:

Out[2]=2

Find the codons (groups of three consecutive nucleotides) with the highest relative frequencies in the list of nucleotides of a gene:

Out[2]=2

Find the noble gases with the highest boiling point and density:

Out[1]=1
Out[2]=2
Out[3]=3

Find the five densest chemical elements:

Out[1]=1

Properties & Relations  (6)Properties of the function, and connections to other functions

TakeLargest[list,n,p] is effectively equivalent to Take[ReverseSort[list,p],n]:

Out[1]=1
Out[2]=2
Out[3]=3

TakeLargest uses NumericalOrder as default ordering function p:

Out[4]=4

Using canonical order can give different results:

Out[5]=5

With numerical inputs, the result of TakeLargest is determined by numerical comparisons:

Out[2]=2
Out[3]=3

Comparisons of non-numerical elements effectively follow canonical order:

Out[5]=5
Out[6]=6

Order is the default ordering function for Sort and ReverseSort:

Out[7]=7

TakeLargest[data,] operates at the first level of the input data:

Out[1]=1
Out[2]=2

If the input has several levels, it is still elements of the first level that will be sorted and extracted:

Out[3]=3
Out[4]=4

Unlike Max, TakeLargest does not return values at deeper levels:

Out[5]=5

When different numerical expressions have the same value, their original order will be preserved:

Out[1]=1
Out[2]=2

TakeLargest[list,n,p] is effectively equivalent to MaximalBy[list,Identity,n,p]:

Out[1]=1
Out[2]=2
Out[3]=3

Take a list of five dates in the current year:

Out[1]=1

Get the two latest of the dates with TakeLargest:

Out[2]=2

Get the second latest of the dates with RankedMax:

Out[3]=3

Possible Issues  (2)Common pitfalls and unexpected behavior

If fewer than the requested number of elements are present, TakeLargest will not evaluate:

Out[1]=1

Use UpTo to get as many elements as possible:

Out[2]=2

If the elements are not comparable, TakeLargest will not evaluate:

Out[1]=1
Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2025).
Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2025).

Text

Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2025).

Wolfram Research (2015), TakeLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeLargest.html (updated 2025).

CMS

Wolfram Language. 2015. "TakeLargest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/TakeLargest.html.

Wolfram Language. 2015. "TakeLargest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/TakeLargest.html.

APA

Wolfram Language. (2015). TakeLargest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeLargest.html

Wolfram Language. (2015). TakeLargest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeLargest.html

BibTeX

@misc{reference.wolfram_2025_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 21-April-2025 ]}

@misc{reference.wolfram_2025_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 21-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 21-April-2025 ]}

@online{reference.wolfram_2025_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 21-April-2025 ]}