Hi --

>> I have an arbitrary number of lists. I want to form all possible
>> combinations from all lists. So if
>> r1=["dog","cat"]
>> r2=[1,2]
>>
>> I want to return [["dog",1],["dog",2],["cat",1],["cat",2]]

Try this:

In [25]: [(x, y) for x in r1 for y in r2]
Out[25]: [('dog', 1), ('dog', 2), ('cat', 1), ('cat', 2)]


Cheers,

Stuart Brorson
Interactive Supercomputing, inc.
135 Beaver Street | Waltham | MA | 02452 | USA
http://www.interactivesupercomputing.com/
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to