How to get the cartesian product of three lists in Python

1 Answer

0 votes
from itertools import product

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

lst = list(product(lst1, lst2, lst3))

print(lst)





'''
run:

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

'''

 



answered Feb 27, 2023 by avibootz

Related questions

1 answer 126 views
2 answers 294 views
2 answers 283 views
2 answers 218 views
...