Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sort a List, in a List of Lists of Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113820] Re: Sort a List, in a List of Lists of Lists
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sun, 14 Nov 2010 06:09:46 -0500 (EST)

Hi,

here is your data

data = {{{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}}}

Mapping Sort on either level 2 or level -2 will do the job, automatically
doing the same
as your hand-written expression with many manually typed Sort commands:

In[3]:= Map[Sort, data, {-2}]

Out[3]= {{{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}}}

In[4]:= Map[Sort, data, {2}]

Out[4]= {{{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}}}


Regards,
Leonid


On Sat, Nov 13, 2010 at 8:59 AM, <leigh.pascoe at inserm.fr> wrote:

> Dear Mathgroup,
>
> 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
>
> {{Sort[{1, 2}], Sort[{2, 1}], Sort[{1, 1}]}, {Sort[{1, 1}],
>   Sort[{1, 1}], Sort[{1, 2}]}, {Sort[{2, 1}], Sort[{2, 2}],
>   Sort[{1, 2}]}, {Sort[{2, 2}], Sort[{1, 2}],
>   Sort[{2, 2}]}, {Sort[{1, 1}], Sort[{2, 1}],
>   Sort[{1, 2}]}, {Sort[{1, 2}], Sort[{2, 2}], Sort[{2, 2}]}}
>
> I must have a blind spot for the correct command. Can someone please
> help me with what should be a straightforward sort. As I want to carry
> this out on several hundred thousand pairs I need a more efficient
> command. Thanks in advance.
>
> LP
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
>
>



  • Prev by Date: how about removing some of the restriction on the free player input?
  • Next by Date: Re: 2-D Butterworth lowpass filter?
  • Previous by thread: Re: Sort a List, in a List of Lists of Lists
  • Next by thread: Re: Sort a List, in a List of Lists of Lists