Re: Sort by buried element in list

• To: mathgroup at smc.vnet.net
• Subject: [mg48914] Re: Sort by buried element in list
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Wed, 23 Jun 2004 02:51:07 -0400 (EDT)
• Organization: Universitaet Leipzig
• References: <cb8vuj\$afh\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

since you don't give an example that can be pasted
into a notebook I havemade my own
example:

lst = Table[{i, {i^2, Random[]}}, {i, 10}]

and the lst should be sorted using the last element in the last entry
and

Sort[lst, Less @@ (Last[Last[#]] & /@ {#1, #2}) &]

Regards
Jens

Steve Gray wrote:
>
>         What's the best way to sort a multilevel list of the following
> type, using as the key the entries 065794, 205347, 000000, 004354,
> etc.? Of course I need all sublists sorted with the key. The entire
> list may be several thousand entries long. Speed is not much of a
> concern. The entries are computed one at a time, and the sort could be
> done at that time or all at once later. I need to (optionally) remove
> entries with duplicate keys, regardless of the other items in the
> entry. The position of the key is known beforehand (obviously).
>
> {{65,98},{44,66},{48,69},{12,54},{98,59},{33,75}},{065794,{0,1,0,1,0,2}}
> {{12,84},(04,79},{92,52},{01,71},{49,80},{96,44}},{205347,{0,3,2,2,2,3}}
> {{83,81},{52,77},{17,29},{33,13},{49,10},{78,78}},{000000,{0,0,0,0,0,0}}
> {{38,25},{74,97},{18,32},{02,08},{43,71},{04,27}},{004354,{0,0,1,1,0,2}}
>
>         The final result for this small sample would be
>
> {{83,81},{52,77},{17,29},{33,13},{49,10},{78,78}},{000000,{0,0,0,0,0,0}}
> {{38,25},{74,97},{18,32},{02,08},{43,71},{04,27}},{004354,{0,0,1,1,0,2}}
> {{65,98},{44,66},{48,69},{12,54},{98,59},{33,75}},{065794,{0,1,0,1,0,2}}
> {{12,84},(04,79},{92,52},{01,71},{49,80},{96,44}},{205347,{0,3,2,2,2,3}}
>
>         Thanks for any info.
>
> Steve Gray

```

• Prev by Date: Re: Re: (**) comments highlighted
• Next by Date: AW: Re: Page breaks and numbers don't seem to work
• Previous by thread: Re: Sort by buried element in list
• Next by thread: Re: Sort by buried element in list