user3000968
user3000968

Reputation: 176

Print Combination in an 2D array in python

I have this array:

[[0, 3], [1, 4], [2]]

i want to display all possible combinations of the array,for example:

0 1 2
3 1 2
0 4 2
3 4 2

the row and the columns of this array is not constant.it changes by the input of the user.

Upvotes: 0

Views: 365

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180471

Use itertools.product:

from itertools import product
l = [[0, 3], [1, 4], [2]]

for prod in product(*l):
    print(prod)

Upvotes: 3

Related Questions