How to get Cartesian product in Python using a generator?
问题 I'm trying to get the Cartesian product of multiple arrays but the arrays are pretty large and I am trying to optimize memory usage. I have tried implementing a generator by using the below code but it just returns that there is a generator at a certain location. import itertools x = [[1,2],[3,4]] def iter_tools(*array): yield list(itertools.product(*array)) print(iter_tools(*x)) When I try the same code but with return instead of yield it works fine. How could I get the cartesian product by