Total python rookie here. I wish to iterate through three lists, where the first two should be recombined in all possible ways while only one value is appended to each combination from third list. So far, I got:
import itertools
list1 = [1,2,3]
list2 = [1,2,3]
list3 = [1,2,3,4,5,6,7,8,9]
for x, y, in itertools.product(list1, list2):
print x, y, list3
This returns:
1 1 [1, 2, 3, 4, 5, 6, 7, 8, 9]
1 2 [1, 2, 3, 4, 5, 6, 7, 8, 9]
1 3 [1, 2, 3, 4, 5, 6, 7, 8, 9]
2 1 [1, 2, 3, 4, 5, 6, 7, 8, 9]
2 2 [1, 2, 3, 4, 5, 6, 7, 8, 9]
2 3 [1, 2, 3, 4, 5, 6, 7, 8, 9]
3 1 [1, 2, 3, 4, 5, 6, 7, 8, 9]
3 2 [1, 2, 3, 4, 5, 6, 7, 8, 9]
3 3 [1, 2, 3, 4, 5, 6, 7, 8, 9]
However, I'd like it to return the following:
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
How can I get to this result?