This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)


SortBy[list, f]
sorts the elements of list in the order defined by applying f to each of them.
  • SortBy[{e1, e2, e3, ...}, f] sorts the ei so that the f[ei] lie in canonical order.
  • If some of the f[ei] are the same, then the canonical order of the corresponding ei is used.
  • SortBy uses the canonical ordering described in the notes for Sort.
  • SortBy can be used on expressions with any head, not only List.
New in 6