Difference between revisions of "Sort Command"
From GeoGebra Manual
m (make-up :italics and example tag) |
|||
Line 2: | Line 2: | ||
{{command|list}} | {{command|list}} | ||
; Sort[List]: Sorts a list of numbers, text objects, or points. | ; Sort[List]: Sorts a list of numbers, text objects, or points. | ||
− | {{Note| Lists of points are sorted by ''x''-coordinates.}} | + | :{{Note| Lists of points are sorted by ''x''-coordinates.}} |
− | {{Example|1=<div> | + | :{{Example|1=<div> |
− | * <code>Sort[{3, 2, 1}]</code> gives you the list ''{1, 2, 3}''. | + | :* <code>Sort[{3, 2, 1}]</code> gives you the list ''{1, 2, 3}''. |
− | * <code>Sort[{"pears", "apples", "figs"}]</code> gives you the list elements in alphabetical order. | + | :* <code>Sort[{"pears", "apples", "figs"}]</code> gives you the list elements in alphabetical order. |
− | * <code>Sort[{(3, 2), (2, 5), (4, 1)}]</code> gives you ''{(2, 5), (3, 2), (4, 1)}''.</div>}} | + | :* <code>Sort[{(3, 2), (2, 5), (4, 1)}]</code> gives you ''{(2, 5), (3, 2), (4, 1)}''.</div>}} |
{{betamanual|version=4.2| | {{betamanual|version=4.2| | ||
− | + | ; Sort[ <Values>, <Keys> ]: Sorts the first list ''Values'' according to the corresponding second list ''Keys''. | |
− | {{Example|1=<code>list1 = {ComplexRoot[x^10-1]}< | + | :{{Example|1=If you want to sort a list of polynomials <code>list1 = {x^3, x^2, x^6}</code> according to degree, create the dependent list of degrees <code>list2 = Zip[Degree[a], a, list1]</code>. After that, <code> Sort[list1, list2]</code> yields the requested ''list3 = {x^2, x^3, x^6}''}} |
− | Polygon[ Sort[ list1, arg(list1) ] ] </code> | + | :{{Example|1=<code>list1 = {ComplexRoot[x^10-1]}</code>, <code>Polygon[Sort[list1, arg(list1)]] </code>}} |
}} | }} | ||
+ | {{note|There is a workaround to sort lists of arbitrary objects which is explained in [[Tutorial:Advanced List Sorting|this tutorial]].}} |
Revision as of 09:31, 10 July 2012
- Sort[List]
- Sorts a list of numbers, text objects, or points.
- Note: Lists of points are sorted by x-coordinates.
- Example:
Sort[{3, 2, 1}]
gives you the list {1, 2, 3}.Sort[{"pears", "apples", "figs"}]
gives you the list elements in alphabetical order.Sort[{(3, 2), (2, 5), (4, 1)}]
gives you {(2, 5), (3, 2), (4, 1)}.
Following text is about a feature that is supported only in GeoGebra 4.2.
|
Note: There is a workaround to sort lists of arbitrary objects which is explained in this tutorial.