3
$\begingroup$

I have a list of disordered numbers. They are collected in different lists. I mean

list = {
   {1, 13, 5},
   {3, 94, 85, 21, 7, 5, 6},
   {2, 5, 9, 88, 4, 15, 36, 4, 8},
   {5, 3, 12, 3},
   {0, 1, 5, 66, 4, 8},
   {5, 8, 7, 4, 6, 2, 55, 98, 4, 65, 4}
   };

I want to have the list in an ordered form but when I use Sortby[list, Last] or Sort[list] nothing happens. How can I sort the list to have the results as

{  {1, 5, 13},
   {3, 5, 6, 7, 21, 85, 94},
   {2, 4, 4, 5, 8, 9, 15, 36, 88},
   {3, 3, 5, 12},
   {0, 1, 4, 5, 8, 66},
   {2, 4, 4, 4, 5, 6, 7, 8, 55, 65, 98}
}
$\endgroup$
5
$\begingroup$

Try

Map[Sort, list]
(*{{1, 5, 13}, {3, 5, 6, 7, 21, 85, 94}, {2, 4, 4, 5, 8, 9, 15, 36, 
88}, {3, 3, 5, 12}, {0, 1, 4, 5, 8, 66}, {2, 4, 4, 4, 5, 6, 7, 8, 
55, 65, 98}}*)
$\endgroup$
  • 4
    $\begingroup$ And there is also the shortcut for mapping: Sort /@ list $\endgroup$ – bill s Jan 2 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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