Re: Sort a List, in a List of Lists of Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg113804] Re: Sort a List, in a List of Lists of Lists
- From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
- Date: Sun, 14 Nov 2010 06:06:46 -0500 (EST)
Hi,
if you take negative numbers for the level spec than it's (in the case
of -2) the second level "from the innerst level in outward direction"
l = {{{{4}}}};
Map[f, l, {2}]
Map[f, l, {-2}]
Cheers
Patrick
On Sat, 2010-11-13 at 14:03 +0100, leigh.pascoe at inserm.fr wrote:
> Ah zut! That's the first thing I tried of course, after scanning the
> help pages. However I neglected to notice the difference between {2}
> and (2) (very difficult to distinguish on my monitor). It's curious
> that the level can be specified by either 2 or -2. Thanks in any case.
>
> LP
>
> Quoting Patrick Scheibe <pscheibe at trm.uni-leipzig.de>:
>
> > Hi,
> >
> > it's the function Map:
> >
> > l = {{{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}}};
> > Map[Sort, l, {-2}]
> >
> > Cheers
> > Patrick
> >
> > On Sat, 2010-11-13 at 00:59 -0500, 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.
> >>
> >>
> >>
> >
> >
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>