Question about permutations (itertools)

Mark Dickinson dickinsm at gmail.com
Mon May 31 11:03:43 EDT 2010


On May 31, 3:04 pm, Vincent Davis <vinc... at vincentdavis.net> wrote:
> For example If I want all possible ordered lists of 0,1 of length 3
> (0,0,0)
> (0,0,1)
> (0,1,1)
> (1,1,1)
> (1,0,1)
> (1,1,0)
> (1,0,0)
> I don't see a way to get this directly from the itertools. But maybe I
> am missing something.

In this case, you're missing itertools.product:

>>> list(itertools.product([0, 1], repeat=3))
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1,
1, 0), (1, 1, 1)]

--
Mark



More information about the Python-list mailing list