How to get the cartesian product of two lists in Python

1 Answer

0 votes
from itertools import product

lst1 = [1, 2, 3, 4]
lst2 = [8, 9]

lst = list(product(lst1, lst2))

print(lst)





'''
run:

[(1, 8), (1, 9), (2, 8), (2, 9), (3, 8), (3, 9), (4, 8), (4, 9)]

'''

 



answered Feb 27, 2023 by avibootz

Related questions

...