1

Lets say I have three lists.

a=[1,2,3,4,5,6,7,8,9,10]
b=[1,2,3,4,5,6,7,8,9,10]
c=[1,2,3,4,5,6,7,8,9,10]

I want to create all permutations with a,b, and c.

from itertools import permutations
a=[1,2,3,4,5,6,7,8,9,10]
b=[1,2,3,4,5,6,7,8,9,10]
c=[1,2,3,4,5,6,7,8,9,10]

perm = permutations([a,b,c])
for i in list(perm): 
   print (i)

This gives

([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

which is not what I'm looking for.

I'm looking for a solution

[1,1,1],[1,2,1],[1,3,1],[1,4,1].....

Is this possible

Charif DZ
  • 14,415
  • 3
  • 21
  • 40

1 Answers1

1

I think you are looking for product:

from itertools import product
a=[1,2,3,4,5,6,7,8,9,10]

perm = product(a, repeat=3)
for i in list(perm): 
   print (i)

If a, b, c not the same list use: product(a, b, c)

Charif DZ
  • 14,415
  • 3
  • 21
  • 40