I would like to write a program to get every sum from a list. For example:
L = [['7'], ['3', '8'], ['8', '1', '0']]
I would like to get:
8 + 3 + 7
8 + 8 + 7
1 + 3 + 7
1 + 8 + 7
0 + 3 + 7
0 + 8 + 7
So, I wrote my program in this way:
for x1 in L[-1]:
for x2 in L[-2]:
for x3 in L[-3]:
print (int(x1) + int(x2) + int(x3))
However, there may be a huge number lists. In this way, I have to write a huge number of for loop. Is there any other way that I can use to write my program?
itertools.product
works well for this question, but is there any way to do not import anything to solve this question?