MathGroup Archive 2010

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

Search the Archive

Re: Howto sum up a list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106966] Re: [mg106913] Howto sum up a list?
  • From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
  • Date: Fri, 29 Jan 2010 07:49:55 -0500 (EST)
  • References: <201001280743.CAA23521@smc.vnet.net>

A solution with Sow and Reap:

In[8]:= Last[Reap[(Sow[Last[#1], First[#1]] & ) /@ MyList, _,
     {#1, Total[#2]} & ]]
Out[8]= {{eggs, 5}, {milk, 2}}


Adriano Pascoletti

2010/1/28 Jonas Stein <news at jonasstein.de>

> How can i sum up the list:
>
> MyList = {{eggs, 4}, {milk, 1}, {eggs, 1}, {milk, 1}}
>
> I want to get something like:
>
> {{eggs, 5},{milk, 2}}
>
> I tyied Tally[], but that ignored the factor 4 in {eggs, 4}
>
> Thank you.
>
> --
> Jonas Stein <news at jonasstein.de>
>
>



  • Prev by Date: Re: Howto sum up a list?
  • Next by Date: Re: Journals dying?, apparently rather slowly (was , I->-I)
  • Previous by thread: Re: Howto sum up a list?
  • Next by thread: Re: Howto sum up a list?