Problem input: two lists [1,2,3] and [4,5,6]
Output: lists that begin with a permutation of [1,2,3] followed by a permutation of [4,5,6]
Example outputs are [1,2,3,4,5,6], [3,2,1,4,5,6], [3,2,1,6,5,4] etc. I want to loop through them using a generator.
I tried with the following script (Python3):
from itertools import permutations
def foo():
perm_1 = permutations([1,2,3])
perm_2 = permutations([4,5,6])
for p1 in perm_1:
for p2 in perm_2:
yield list(p1) + list(p2)
f = foo()
for ls in f:
print(ls)
As outputs I get
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 6, 5]
[1, 2, 3, 5, 4, 6]
[1, 2, 3, 5, 6, 4]
[1, 2, 3, 6, 4, 5]
[1, 2, 3, 6, 5, 4]
As you can see, the permutations of the first list are never used and e.g output [3,2,1,4,5,6] is never produced.