I have this code:
list_1 = [11, 22]
list_2 = [33, 44, 55 ,66]
list_3 = [77, 88 ,99]
I want to sum each elements in lists. i.e. 11 + 33 + 77, 11 + 33 + 88, … 22 + 33 + 77, 22 + 33 + 88… and put all the sums into a final list
I have these lines:
list_1 = [11, 22]
list_2 = [33, 44, 55 ,66]
list_3 = [77, 88 ,99]
result = []
for L_1 in list_1:
for L_2 in list_2:
for L_3 in list_3:
result.append(L_1 + L_2 + L_3)
print result # to output all elements
print list(set(result)) # to not showing duplicates
The codes work well but looked clumsy. If there are 20 or more lists to take part in the calculation, it doesn’t looked good at all.
Could you please show me a better way?