Re: Sorting and Selecting in MultiLevel Lists?

• To: mathgroup at smc.vnet.net
• Subject: [mg31175] Re: Sorting and Selecting in MultiLevel Lists?
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Tue, 16 Oct 2001 01:18:52 -0400 (EDT)
• Organization: Universitaet Leipzig
• References: <9qbi2c\$2d7\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

since you compute x^2+y^2 twice in every comparsion it seems to
be better to compute thist value one for every pair and remove
it when you have sorted the pairs.

Take[#, 2] & /@ Sort[Append[#, Dot[#, #]] & /@ myList, Last[#1] <
Last[#2] &]

Regards
Jens

aes wrote:
>
> Suppose I want to Sort, or Select from, a multilevel list, e.g.
>
>         myList =  { {x1,y1},  {x2,y2},  {x3,y3}, . . . }
>
> with a Sort or Select criterion that's some function of the xn and yn values
>
> For example, I can sort the above list on the value of x^2 + y^2 by using
>
>     Sort[myList, (Take[#1, 1][[1]]^2 + Take[#1, 2][[1]]^2) <
>                         (Take[#2, 1][[1]]^2 + Take[#2, 2][[1]]^2) &]
>
> Question:  Is there an easier way to get at the "x" and "y" values associated
> with the #1 and #2 arguments in Sort, or with the # argument in Select, than the
> awkward   Take[#,m][[n]]   notation used here?

```

• Prev by Date: Re: Simplex visualization
• Next by Date: RE: Plot-Function
• Previous by thread: Re: Sorting and Selecting in MultiLevel Lists?
• Next by thread: Resume calculation