'Cross join addition with 2D lists
I created a post earlier regarding cross joining two lists with addition. However, suppose I have two lists that are two dimensional.
For Example:
list1 = ([5,2,8],[1,2,3])
list2 = ([11,6,3],[3,2,1])
sum_list = []
My expected output would be:
print (sum_list)
Output:
[16,11,8],[8,7,6],
[13,8,5], [5,4,3],
[19,14,11],[11,10,9],
[12,7,4],[4,3,2],
[13,8,5],[5,4,3],
[14,9,6],[6,5,4]
Solution 1:[1]
I honestly do not know why you would do this, but heres the code:
list1 = ([5,2,8],[1,2,3])
list2 = ([11,6,3],[3,2,1])
sum_list = []
for i in list1:
for j in i:
for k in list2:
templ=[]
for l in k:
templ.append(j+l)
sum_list.append(templ)
print(sum_list)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TheRavenSpectre |
