Tuesday, 20 August 2013

Python itertools.product Input Formatting

Python itertools.product Input Formatting

I wish to execute the following code:
temp = []
temp.append([1,2])
temp.append([3,4])
temp.append([5,6])
print list(itertools.product(temp[0],temp[1],temp[2]))
However, I would like to execute it for temp with arbitrary length. I.e.
something more like:
print list(itertools.product(temp))
How do I format the input correctly for itertools.product to produce the
same result in the first segment of code without explicitly knowing how
many entries there are in temp?

No comments:

Post a Comment