Generating all combinations
Mark Dickinson
dickinsm at gmail.com
Sun May 31 17:11:22 EDT 2009
On May 31, 9:23 pm, Johannes Bauer <dfnsonfsdu... at gmx.de> wrote:
> I'm trying to write a function in Python which does the following: For a
> number of arguments which are all lists, return a list (or generator)
> which yields all tuples of combination. E.g:
>
> foofunction()
> # returns [ ]
Are you sure that's what you want? I'd expect [()] here (on the
basis that the empty product is a one-element set). And
indeed that's what itertools.product gives:
>>> import itertools
>>> list(itertools.product())
[()]
> foofunction([1, 2, 3])
> # returns [ (1), (2), (3) ]
Presumably you mean [(1,), (2,), (3,)] here?
Mark
More information about the Python-list
mailing list