I am trying to find a way to combine 2 lists and then sum the combined list in a specific way. The sum of the 2 previous elements must be summed to the next element.
Ex : the sum of the first combination, ((1, 2), (4,)) , should be (3,7,6), because 1+2=3, 3+4=7, 2+4=6.
And then be printed side by side : ((1, 2), (4,)) (3,7,6) IF it ( both the combination and its sum) do not contain a certain element ( somehow alredy inserted).
Here is my code and my examples:
a=[1,2,3]
b=[4,5,6]
import itertools
sets = [a,b];
ks = [2, 1,]
combinations = itertools.product(*[itertools.combinations(set, k) for set, k in zip(sets, ks)])
for combination in combinations:
print (combination)