2
$\begingroup$

Imagine I have this data.

data

I want to sort it so that it takes the form:

{{<larger>, <smaller>}, {<larger>, <smaller>}, ...}, 

Any help would be appreciated.

$\endgroup$
  • 6
    $\begingroup$ try Map[ReverseSort]@list or ReverseSort/@list? $\endgroup$ – kglr Oct 19 at 22:58
3
$\begingroup$
lists = {{0.959531`,1.72455`},{1.39025`,1.70444`},{1.53595`,0.207495`}, 
  {0.117589`,0.270531`},{0.815728`,1.53551`},{1.43189`,0.0795958`}, 
  {0.959939`,0.742054`},{1.92875`,1.77258`},{0.494335`,0.588112`}, 
  {1.22158`,1.08751`},{0.8228`,0.309531`},{1.41939`,0.833903`}}


MatrixForm[lists]

enter image description here

 sorted = Map[ReverseSort] @ lists;

 MatrixForm[sorted]

enter image description here

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Interesting, some of the 0s get read as @ by TextRecognize on my machine (12.1.1 for Linux x86 (64-bit) (June 19, 2020)). Also it is a bit ironic that TextRecognize does not recognize Mathematica output. $\endgroup$ – Natas Oct 20 at 9:02
2
$\begingroup$
Sort[#, Greater] & /@ {{1, 2}, {3, 3}, {5, 6}, {3.14, π}}

Or

{{1, 2}, {3, 3}, {5, 6}, {3.14, π}} /. {x_?NumberQ, 
   y_?NumberQ} :> {Max[x, y], Min[x, y]}

{{2, 1}, {3, 3}, {6, 5}, {π, 3.14}}

| improve this answer | |
$\endgroup$

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