MathGroup Archive 2007

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

Search the Archive

Re: Re: Another question on lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80711] Re: [mg80641] Re: [mg80618] Another question on lists
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Wed, 29 Aug 2007 04:24:08 -0400 (EDT)
  • References: <27088617.1188205442155.JavaMail.root@m35> <200708280603.CAA14009@smc.vnet.net>

DrMajorBob wrote:

>Here's an example:
>
>sample = Array[
>   RandomInteger[{1, 10}, {RandomInteger[{3, 10}]}] &, {15}]
>Length /@ %
>
>{{5, 7, 7, 1, 2, 5, 2, 7, 3}, {3, 4, 3, 8, 8}, {1, 4, 6, 6, 1, 6,
>   3}, {4, 6, 1, 9, 9, 7, 3, 5, 10}, {9, 1, 4, 2, 7, 1, 5}, {2, 8, 2,
>   4, 7, 3, 8}, {2, 10, 4, 7, 2, 10, 3}, {10, 5, 10, 6, 5, 10, 4, 3,
>   4}, {5, 2, 3, 10, 8}, {5, 1, 7}, {1, 5, 8, 4, 8, 5, 8, 2}, {3, 3, 8,
>    5, 1, 7}, {6, 10, 1, 6, 3, 5, 7, 6, 1, 7}, {3, 5, 1, 6, 6}, {10,
>   10, 9, 3, 9}}
>
>{9, 5, 7, 9, 7, 7, 7, 9, 5, 3, 8, 6, 10, 5, 5}
>
>Last@SortBy[sample, Length]
>
>{6, 10, 1, 6, 3, 5, 7, 6, 1, 7}
>
>or
>
>sample[[Ordering[sample, -1, Length[#1] < Length[#2] &]]]
>
>{{6, 10, 1, 6, 3, 5, 7, 6, 1, 7}}
>  
>
Just a minor comment that the third argument of Ordering is not needed 
in this case, since the default order used sorts by length of list 
first. Try:

sample[[Ordering[sample,-1]]]

instead.

Carl Woll
Wolfram Research

>Bobby
>
>On Sun, 26 Aug 2007 22:20:22 -0500, Mauricio Esteban Cuak  
><cuak2000 at gmail.com> wrote:
>
>  
>
>>Hello again.Thank you very much for your previous help. However, I
>>seem to stumble on another rock:
>>
>>I  have a list of n sub-lists with different number of elements. I
>>want to select the list with the highest number of elements.
>>I tried to combine the Select function with Lenght but couldn't do it:
>>
>>Select[list, Length /@ list >= Max[Length /@ list] &]
>>
>>Thanks for reading.
>>
>>Regards,
>>
>>cd
>>
>>P.D.: Any tips,websites, books, on how to learn some basic programming
>>on Mathematica?
>>I'm slowly beginning to read "The Mathematica Book"...should I just
>>concentrate on that?
>>
>>
>>    
>>
>
>
>
>  
>



  • Prev by Date: Computer Graphics Positions at Wolfram Rsearch
  • Next by Date: Re: fit a BinomialDistribution to exptl data?
  • Previous by thread: Re: Another question on lists
  • Next by thread: Re: Re: Re: Another question on lists