Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Iterate Through a List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77404] Re: Iterate Through a List
  • From: "Drago Ganic" <dganic at vodatel.net>
  • Date: Thu, 7 Jun 2007 06:32:40 -0400 (EDT)
  • References: <f4697t$3ps$1@smc.vnet.net>

Hi,
just use First/@yourList

e.g.
lst = {{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}}

First/@lst
{1,1,2,2,4,4}

Greetings,
drago
"Nick" <hoffmannick at gmail.com> wrote in message 
news:f4697t$3ps$1 at smc.vnet.net...
> 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!
> -Nick
>
> 




  • Prev by Date: Re: v6: still no multiple undo?
  • Next by Date: Re: Best practice for Mathematica package development
  • Previous by thread: Re: Iterate Through a List
  • Next by thread: Re: Iterate Through a List