Re: Iterate through a list help

• To: mathgroup at smc.vnet.net
• Subject: [mg77310] Re: [mg77187] Iterate through a list help
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Wed, 6 Jun 2007 07:27:26 -0400 (EDT)
• References: <17582220.1181096375794.JavaMail.root@m35>

```Tally counts occurrences in a list.

First /@ {{1, 0}, {1, 1}, {2, x + x^2 + x^4}, {2,
1 + x + x^2 + x^4}, {4, x + x^2}, {4, 1 + x + x^2}, {4,
x + x^4}, {4, 1 + x + x^4}, {4, x^2 + x^4}, {4, 1 + x^2 + x^4}, {4,
x^3 + x^4}, {4, 1 + x^3 + x^4}, {4, x + x^2 + x^3 + x^4}, {4,
1 + x + x^2 + x^3 + x^4}, {5, x + x^3}, {5, 1 + x + x^3}, {5,
x^2 + x^3}, {5, 1 + x^2 + x^3}, {5, x + x^3 + x^4}, {5,
1 + x + x^3 + x^4}, {5, x^2 + x^3 + x^4}, {5,
1 + x^2 + x^3 + x^4}, {8, x}, {8, x^2}, {8, x^3}, {8, x^4}, {8,
1 + x}, {8, 1 + x^2}, {8, 1 + x^3}, {8, x + x^2 + x^3}, {8,
1 + x + x^2 + x^3}, {8, 1 + x^4}}
Tally[%]

{1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 8, \
8, 8, 8, 8, 8, 8, 8, 8, 8}

{{1, 2}, {2, 2}, {4, 10}, {5, 8}, {8, 10}}

Bobby

On Tue, 05 Jun 2007 05:48:49 -0500, Nick <hoffmannick at gmail.com> wrote:

> Hello! I'm (somewhat) new to Mathematica and I  need help to iterating
> through a list and counting the occurrence of a number.
>
> My list looks like:
>
> {{1,0},{1,1},{2,x+x^2+x^4},{2,1+x+x^2+x^4},{4,x+x^2},{4,1+x+x^2},{4,x
> +x^4},{4,1+x+x^4},
> {4,x^2+x^4},{4,1+x^2+x^4},{4,x^3+x^4},{4,1+x^3+x^4},{4,x+x^2+x^3+x^4},
> {4,1+x+x^2+x^3+x^4},
> {5,x+x^3},{5,1+x+x^3},{5,x^2+x^3},{5,1+x^2+x^3},{5,x+x^3+x^4},{5,1+x
> +x^3+x^4},{5,x^2+x^3+x^4},
> {5,1+x^2+x^3+x^4},{8,x},{8,x^2},{8,x^3},{8,x^4},{8,1+x},{8,1+x^2},
> {8,1+x^3},{8,x+x^2+x^3},{8,1+x+x^2+x^3},{8,1+x^4}}
>
> The number that I would need to keep track of is the first in each
> sub-
> list.
>
> So for the first couple {{1,0},{1,1},{2,x+x^2+x^4},{2,1+x+x^2+x^4},
> {4,x
> +x^2},........
>
> I would need to keep track of 1,1,2,2,4........
>
> It will not always be 1,2,4,5,8's.  The numbers may be completely
> different on each pass.  Each sublist may be composed of more items
> but the number that I need to keep track of will always be the 1st in
> the sub-list.  Any help or suggestions that you can give me will be
> greatly appreciated.  Thanks so much!
>
>
>

--
DrMajorBob at bigfoot.com

```

• Prev by Date: Re: Re: What to do in v. 6 in place of Miscellaneous`RealOnly
• Next by Date: Re: Re: Problem with Mathematica 6
• Previous by thread: Re: Iterate through a list help
• Next by thread: Re: Iterate through a list help