Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I sort a list and also get a list of indices that sort this list? For example: primary list is a


sorted list is b


and also return list c

share|improve this question
up vote 9 down vote accepted

To get list b, you need Sort[]: Sort[{1, 4, 6, 7, 0, 2}, GreaterEqual].

To get list c, you need Ordering[]: Ordering[{1, 4, 6, 7, 0, 2}, All, GreaterEqual].

share|improve this answer
+1, Beat me by 20 seconds :-) – Heike Jun 24 '12 at 11:59
@Heike: I guess there is such a thing as being in the right place at the right time... :) – J. M. Jun 24 '12 at 12:00
@J.M. : Thank you – Vahid Iraji Jun 24 '12 at 12:03
Also, if you need both, you might first do Ordering and then b=a[[c]] – Rojo Jun 24 '12 at 14:00
@Rojo: that's a good point with respect to saving sorting effort. :) – J. M. Jun 24 '12 at 14:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.