[Numpy-discussion] how do I list all combinations

Charles R Harris charlesr.harris@gmail....
Wed Dec 26 14:52:27 CST 2007

On Dec 26, 2007 1:22 PM, Mathew Yeates <myeates@jpl.nasa.gov> wrote:

> Hi
> I've been looking at "fromfunction" and itertools but I'm flummoxed.
> 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?

It's a mixed radix counter. Emulate the usual add and carry with a list of
digits using the length of the corresponding list as the radix at that
position. Sorta like an abacus, but with different numbers of beads in each

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071226/986514cb/attachment.html 

More information about the Numpy-discussion mailing list