How to use product() with chain() and range() to get cartesian product of multiple lists in Python

1 Answer

0 votes
from itertools import *      

lst1 = ('A', 'B', 'C')      
lst2 = ('X', 'Y')      

p = list(product(chain(range(1, 3), lst1), lst2,))
print(p)


'''
run:

[(1, 'X'), (1, 'Y'), (2, 'X'), (2, 'Y'), ('A', 'X'), ('A', 'Y'), ('B', 'X'), ('B', 'Y'), ('C', 'X'), ('C', 'Y')]

'''

 



answered May 25, 2019 by avibootz

Related questions

1 answer 117 views
1 answer 130 views
2 answers 298 views
2 answers 288 views
2 answers 223 views
...