Re: Another question on lists

• To: mathgroup at smc.vnet.net
• Subject: [mg80641] Re: [mg80618] Another question on lists
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Tue, 28 Aug 2007 02:03:46 -0400 (EDT)
• References: <27088617.1188205442155.JavaMail.root@m35>

```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}}

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] &]
>
>
> 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?
>
>

--

DrMajorBob at bigfoot.com

```

• Prev by Date: Mistake in applying a rule
• Next by Date: Re: Another question on lists
• Previous by thread: Another question on lists
• Next by thread: Re: Re: Another question on lists