ReverseSortBy

ReverseSortBy[list,f]

sorts the elements of list using the reverse canonical order defined by applying f to each of them.

ReverseSortBy[list,f,p]

sorts the elements of list using the function p to compare pairs of results of applying f to each element.

ReverseSortBy[f]

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

Details

  • ReverseSortBy[{e1,e2,e3,},f] sorts the ei so that the f[ei] lie in reverse canonical order.
  • If some of the f[ei] are the same, then the reverse canonical order of the corresponding ei is used.
  • ReverseSortBy[list,f] is equivalent to reversing the result of SortBy[list,f].
  • In the result of ReverseSortBy[{e1,e2,e3,},f,p], element ei will be sorted before ej if p[f[ei],f[ej]] is -1 or False.
  • ReverseSortBy[list,{f1,f2,}] breaks ties by successively using the values obtained from the fi.
  • ReverseSortBy can be used on expressions with any head, not only List.
  • ReverseSortBy[f][list] is equivalent to ReverseSortBy[list,f].

Examples

open allclose all

Basic Examples  (5)

Reverse sort a list of lists by the last element of each sublist:

Reverse sort by the total of each sublist:

Reverse sort a list of integers by their values modulo 3:

Reverse sort elements of an Association by their values modulo 3:

Use ReverseSortBy as an operator form:

Scope  (5)

Reverse sort by numerical value:

The default reverse order ranks these symbolically:

Reverse sort by absolute numerical value:

Reverse sort by Re, Im, Arg and Abs:

Reverse sort dates by converting to their absolute time form:

Reverse sort complex numbers by their modulus using numerical order:

Using canonical order gives a different result:

Reverse sort by string length:

Reverse sort the strings using Greater as the ordering function:

Generalizations & Extensions  (1)

ReverseSortBy can be used on expressions with any head:

Applications  (1)

Reverse sort mathematically equivalent expressions by different criteria:

Reverse sort by LeafCount:

Reverse sort by size of error for numerical evaluation with machine numbers at :

Properties & Relations  (1)

ReverseSortBy[list,f] is equivalent to Reverse[SortBy[list,f]], even in the presence of ties:

Use ReverseSortBy[list,{f}] to avoid reordering ties:

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

Text

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

CMS

Wolfram Language. 2019. "ReverseSortBy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ReverseSortBy.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_reversesortby, author="Wolfram Research", title="{ReverseSortBy}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/ReverseSortBy.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_reversesortby, organization={Wolfram Research}, title={ReverseSortBy}, year={2019}, url={https://reference.wolfram.com/language/ref/ReverseSortBy.html}, note=[Accessed: 21-November-2024 ]}