I have the following bit of code:
a = [0,1,2,3,4]
b = range(6)
p = itertools.permutations(a)
p2 = itertools.product(b,b,b,b,b)
for pos in p:
for shift in p2:
print(pos,shift)
which prints out:
(0, 1, 2, 3, 4) (0, 0, 0, 0, 0)
(0, 1, 2, 3, 4) (0, 0, 0, 0, 1)
(0, 1, 2, 3, 4) (0, 0, 0, 0, 2)
(0, 1, 2, 3, 4) (0, 0, 0, 0, 3)
(0, 1, 2, 3, 4) (0, 0, 0, 0, 4)
...
(0, 1, 2, 3, 4) (5, 5, 5, 5, 5)
The outer loop is executed only once. If I do
for pos in p:
print(pos)
the loop executes just fine:
(0, 1, 2, 3, 4)
(0, 1, 2, 4, 3)
...
(4, 3, 2, 1, 0)
Why is this happening, and how do I make the two nested for loops work? Note that I have tried looping over list(p) instead of just p and it doesn't make a difference.