1
$\begingroup$

I already know the sorted positions, so I want to sort based on that.

Say, I have list of {1, 3}, I want the sorted position to be {2, 1}, as 2 is the second element, 3 and 1 is the first element 1.

How should I write the sort function to be most simple.

Should I write something like Sort[{1, 3}, {2, 1}{{_}}] where _ should represent the indice of that element in the original list.

$\endgroup$

closed as off-topic by yohbs, happy fish, MarcoB, Yves Klett, mikado Apr 30 '17 at 14:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – yohbs, happy fish, MarcoB, Yves Klett, mikado
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    $\begingroup$ {1,3}[[{2,1}]]? More generally, list[[Ordering[list]]] $\endgroup$ – kglr Apr 27 '17 at 17:43
4
$\begingroup$
{1,3}[[{2,1}]]

{3, 1}

Generally,

list = {1, 3};
positions = {2,1};
list[[positions]]

{3, 1}

$\endgroup$

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