# 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.

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 all close all

## Basic Examples(5)

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

 In:= Out= Reverse sort by the total of each sublist:

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

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

 In:= Out= Use ReverseSortBy as an operator form:

 In:= Out= ## Properties & Relations(1)

Introduced in 2019
(12.0)