DOCUMENTATION CENTER SEARCH
Mathematica
>
Rearranging & Restructuring Lists
>
Built-in
Mathematica
Symbol
Sort
Ordering
OrderedQ
Tally
Nearest
See Also »
|
Numerical Data
Rearranging & Restructuring Lists
New in 6.0: List Manipulation
More About »
SortBy
SortBy
[
list
,
f
]
sorts the elements of
list
in the order defined by applying
f
to each of them.
MORE INFORMATION
SortBy
[{
e
1
,
e
2
,
e
3
,
...
},
f
]
sorts the
e
i
so that the
f
[
e
i
]
lie in canonical order.
If some of the
f
[
e
i
]
are the same, then the canonical order of the corresponding
e
i
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
.
EXAMPLES
CLOSE ALL
Basic Examples
(2)
Sort a list of lists by the last element of each sublist:
In[1]:=
Out[1]=
Sort by the total of each sublist:
In[2]:=
Out[2]=
Sort a list of integers by their values modulo 3:
In[1]:=
Out[1]=
Scope
(4)
Generalizations & Extensions
(1)
Applications
(2)
Properties & Relations
(1)
SEE ALSO
Sort
Ordering
OrderedQ
Tally
Nearest
MORE ABOUT
Numerical Data
Rearranging & Restructuring Lists
New in 6.0: List Manipulation
New in 6
© 2008 Wolfram Research, Inc.