# TakeSmallest

TakeSmallest[list,n]

gives the n numerically smallest elements in list, sorted in ascending order.

TakeSmallest[listprop,n]

gives the property prop for the n smallest elements in list.

TakeSmallest[n]

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

# Details and Options

• TakeSmallest sorts by numerical magnitude.
• It handles numeric objects with real values, Quantity objects, and DateObject constructs.
• In TakeSmallest[listprop,n], possible forms for prop include:
•  "Element" gives each element itself "Index" gives the index for each element {prop1,prop2,…} a list of multiple forms All gives an association with element and index
• TakeSmallest has option ExcludedForms. With the default setting , TakeSmallest drops elements that are None, Null, or Indeterminate, or have head Missing.
• The setting ExcludedForms->{p1,p2,} specifies that expressions matching any of the pi should be excluded from results generated by TakeSmallest.
• TakeSmallest[list,UpTo[n]] takes n smallest elements, or as many as are available.
• TakeSmallest[assoc,n] gives an association of length n by taking the n smallest values in assoc, preserving their keys.
• TakeSmallest[n][list] is equivalent to TakeSmallest[list,n].

# Examples

open allclose all

## Basic Examples(5)

Take the two smallest numbers in a list:

Do the same using the operator form of TakeSmallest:

Take the two smallest values in an association:

Get the two smallest quantities in a list of Quantity objects:

Quantities can be present in multiple units:

Get the two least recent dates in a list of DateObject constructs:

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

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

## Scope(4)

Get the two smallest elements in a list:

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

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

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

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

Get the three planets with the smallest radii:

Get the release dates of the five oldest James Bond movies:

## Options(1)

### ExcludedForms(1)

The option ExcludedForms->list specifies that elements matching any of the forms in list should be dropped before the elements are compared:

The default value excludes some common non-numeric expressions but leaves most symbolic expressions:

## Applications(2)

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

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

## Possible Issues(2)

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

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

## Neat Examples(1)

Take the five least dense chemical elements:

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

#### Text

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

#### CMS

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

#### APA

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

#### BibTeX

@misc{reference.wolfram_2022_takesmallest, author="Wolfram Research", title="{TakeSmallest}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/TakeSmallest.html}", note=[Accessed: 08-June-2023 ]}

#### BibLaTeX

@online{reference.wolfram_2022_takesmallest, organization={Wolfram Research}, title={TakeSmallest}, year={2019}, url={https://reference.wolfram.com/language/ref/TakeSmallest.html}, note=[Accessed: 08-June-2023 ]}