MathGroup Archive 2007

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

Search the Archive

Re: Iterate through a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76948] Re: Iterate through a list
  • From: Donald DuBois <dfd01 at comcast.net>
  • Date: Wed, 30 May 2007 05:30:31 -0400 (EDT)

You can pull out the first member of each sublist
and count the number of occurences of each element
by doing the following:


In[27]:= lst = {{1, 0}, {1, 1}, {2, x + x^2 + x^4}, {2, 
   1 + x + x^2 + x^4}, {4, x + x^2}}

Out[27]= {{1, 0}, {1, 1}, {2, x + x^2 + x^4}, {2, 
  1 + x + x^2 + x^4}, {4, x + x^2}}

In[29]:= lst[[All, 1]]

Out[29]= {1, 1, 2, 2, 4}

In[30]:= Tally[%]

Out[30]= {{1, 2}, {2, 2}, {4, 1}}

Hope this helps.
Don


  • Prev by Date: Another strange cursor behavior in 6.0
  • Next by Date: Re: Polynomial to List
  • Previous by thread: Re: Iterate through a list
  • Next by thread: Re: Iterate through a list