efficiency of Python's itertools.product()
问题 So I'm looking at different ways to compute the Cartesian product of n arrays, and I came across the rather elegant solution (here on SO) of using the following code: import itertools for array in itertools.product(*arrays): print array Looking at the python doc page (I'm using 2.7, btw) for itertools.product() , it says the code is equivalent to the following: def product(*args, **kwds): # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --> 000 001 010 011 100