# Adding multiplied corresponding elements from two different lists

I have two lists with same length:

list00={10, 6, 8, 6, 9, 7, 9, 5, 7, 10};
list0={0, 5, 2, 4, 3, 0, 3, 3, 0, 5};


and another list:

mainlist={1, 2, 4, 10};


I wish to sum multiplied corresponding elements of list00 and list0 according to mainlist:

sum=10*0+6*5+6*4+10*5;


my code is:

sum = 0; Do[  sum += list0[[i]]*list00[[i]]
, {i, mainlist}]


Question:

If I have two distinguishable and different mainlists for list00 and list0 seperately, how can we do this process (adding multiplied corresponded elements):

list00={10, 6, 8, 6, 9, 7, 9, 5, 7, 10};
list0={0, 5, 2, 4, 3, 0, 3, 3, 0, 5};

mainlist00={1, 2, 4, 10};
mainlist0={1, 3, 5, 8};

*desired result:* 10*0+6*2+6*3+10*3;


list00 = {10, 6, 8, 6, 9, 7, 9, 5, 7, 10};
list0 = {0, 5, 2, 4, 3, 0, 3, 3, 0, 5};

mainlist00 = {1, 2, 4, 10};
mainlist0 = {1, 3, 5, 8};

Times @@@ Transpose[{list00[[mainlist00]], list0[[mainlist0]]}] // Total


60

or using Dot

list00[[mainlist00]].list0[[mainlist0]]


60

With one "mainlist" it would be

mainlist = {1, 2, 4, 10};

Times @@@ Transpose[{list00, list0}][[mainlist]] // Total


104

Or

list00[[mainlist]].list0[[mainlist]]


104

• +1 for the Dot method Jul 15, 2017 at 2:27
☺ = #[[#2]].#3[[#4]] & @@ # &;

☺ @ {list00, mainlist, list0, mainlist}


104

☺ @ {list00, mainlist00, list0, mainlist0}


60

• ... this is the Dot product of the selected Parts of the of the two lists.
– kglr
Jul 14, 2017 at 20:43