Re: Sort a List, in a List of Lists of Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg113816] Re: Sort a List, in a List of Lists of Lists
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sun, 14 Nov 2010 06:09:01 -0500 (EST)
On 11/13/10 at 12:59 AM, leigh.pascoe at inserm.fr wrote: >I have a lsit of Lists of Lists: >{{{1,2},{2,1},{1,1}},{{1,1},{1,1},{1,2}},{{2,1},{2,2},{1,2}},{{2,2}, >{1,2},{2,2}},{{1,1},{2,1},{1,2}},{{1,2},{2, 2},{2,2}}} >I would like to sort the elements in the lowest level of brackets to >give >{{{1, 2}, {1, 2}, {1, 1}}, {{1, 1}, {1, 1}, {1, 2}}, {{1, 2}, {2, >2}, {1, 2}}, {{2, 2}, {1, 2}, {2, 2}}, {{1, 1}, {1, 2}, {1, 2}}, >{{1, 2}, {2, 2}, {2, 2}}} >i.e retaining the same structure with the paired elements in the >original order. I can't seem to get the syntax right to do this >apart from the obvious A simple way to accomplish this is to use Map with a level specification, that is In[2]:= Map[Sort, list, {2}] Out[2]= {{{1, 2}, {1, 2}, {1, 1}}, {{1, 1}, {1, 1}, {1, 2}}, {{1, 2}, {2, 2}, {1, 2}}, {{2, 2}, {1, 2}, {2, 2}}, {{1, 1}, {1, 2}, {1, 2}}, {{1, 2}, {2, 2}, {2, 2}}}