Re: Sort by buried element in list

*To*: mathgroup at smc.vnet.net*Subject*: [mg48915] Re: [mg48899] Sort by buried element in list*From*: DrBob <drbob at bigfoot.com>*Date*: Wed, 23 Jun 2004 02:51:11 -0400 (EDT)*Organization*: Deep Space Engineering Corps*References*: <200406220932.FAA10308@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

data={{{{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}}}}; key[{a_List,b_List}]:=First@b data[[Ordering[key/@data]]] {{{{83,81},{52,77},{17,29},{33,13},{49,10},{78,78}},{ 0,{0,0,0,0,0,0}}},{{{38,25},{74,97},{18,32},{2,8},{ 43,71},{4,27}},{4354,{0,0,1, 1,0,2}}},{{{65,98},{44,66},{48,69},{12,54},{98,59},{33,75}},{ 65794,{0,1,0,1,0,2}}},{{{12, 84},{4,79},{92,52},{1,71},{49,80},{96,44}},{205347,{0,3,2,2,2,3}}}} Bobby On Tue, 22 Jun 2004 05:32:12 -0400 (EDT), Steve Gray <stevebg at adelphia.net> 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 > > > -- DrBob at bigfoot.com www.eclecticdreams.net/index.html

**References**:**Sort by buried element in list***From:*Steve Gray <stevebg@adelphia.net>