Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'merging similar sublists' topicStudent Support Forum > General > "merging similar sublists"

Next Comment >Help | Reply To Topic
Author Comment/Response
yiannis
04/21/06 10:57am

Hi,

I have the following list structure:

ll={{2,a},{6,b},{6,a},{13,b},{27,a},{15,c},...
,{45,d},...,{28,d},...}

and I want to produce something like:

newll={{2+6+27+...,a},{6+13+...,b},{15,c},...,{45+28+...,d},...},

that is, I want to merge the sublists which have the same SECOND element and at the same time SUM their first elements to produce a new sublist of the form: {SUM[first elements], common second element}

Thanks in advance,
Y.


URL: ,

Subject (listing for 'merging similar sublists')
Author Date Posted
merging similar sublists yiannis 04/21/06 10:57am
Re: merging similar sublists yehuda ben-s... 04/22/06 05:12am
Re: merging similar sublists ravi 04/23/06 08:33am
Re: merging similar sublists ravi 04/23/06 12:50pm
Next Comment >Help | Reply To Topic