Previous Up Next

2.37.18  Sort : sort

sort takes as argument a list or an expression.

sort accepts an optionnal second argument, which is a bivariate function returning 0 or 1. If provided, this function will be used to sort the list, for example (x,y)->x>=y may be used as second argument to sort the list in decreasing order. This may also be used to sort list of lists (that sort with one argument does not know how to sort).
Input :

sort([3,4,2],(x,y)->x>=y)

Output :

[4,3,2]

Previous Up Next