[Numpy-discussion] how do I list all combinations

Mathew Yeates myeates@jpl.nasa....
Wed Dec 26 15:04:36 CST 2007


yes, I came up with this and may use it. Seems like it would be insanely 
slow but my problem is small enough that it might be okay.

Thanks


Keith Goodman wrote:
> On Dec 26, 2007 12:22 PM, Mathew Yeates <myeates@jpl.nasa.gov> wrote:
>   
>> 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]]
>>
>> It's obvious when the number of lists is not arbitrary. But what if
>> thats not known until runtime?
>>     
>
> Would this work?
>
> Make a function that takes two inputs (a list of lists and a list) and
> returns a list of lists that contains all possible combinations.
> Iterate through all lists by calling the function with the output of
> the previous call (a list of lists) and the next list.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>   




More information about the Numpy-discussion mailing list