-1

Hello here is what I want to do

ListToPerm = [[1,2], [1,2,3], [1,2]]

Ouput
[1,1,1]
[1,1,2]
[1,2,1]
...
[2,3,2]

I can't seem to find anything that does this. Any answer does not do this desired output.

AMC
  • 2,642
  • 7
  • 13
  • 35
Y Mika
  • 71
  • 1
  • 6
  • 3
    [itertools.product](https://docs.python.org/3/library/itertools.html#itertools.product) – G. Anderson Mar 25 '20 at 19:39
  • Does this answer your question? [All combinations of a list of lists](https://stackoverflow.com/questions/798854/all-combinations-of-a-list-of-lists) – G. Anderson Mar 25 '20 at 19:42
  • Please clarify what exactly the issue is. See [ask], [help/on-topic]. – AMC Mar 25 '20 at 19:50

1 Answers1

1

Expanding on G.Anderson's comment that you'll want itertools.product:

from itertools import product

l = [[1,2], [1,2,3], [1,2]]

list(product(*l))
[(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (1, 3, 1), (1, 3, 2), (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2), (2, 3, 1), (2, 3, 2)]
C.Nivs
  • 12,353
  • 2
  • 19
  • 44