2

What is the most pythonic way of getting the following:

(False, False, False)
(False, False, True)
(False, True, False)
(False, True, True)
...

I have n variables, each taking a value True or False, how can I combine these? I was thinking of using range(n) and then checking the bits of generated integers, but this seems too hacky.

Moronic
  • 141
  • 2
  • 9

1 Answers1

10

Probably simplest:

>>> list(itertools.product([False, True], repeat=3))

[(False, False, False),
 (False, False, True),
 (False, True, False),
 (False, True, True),
 (True, False, False),
 (True, False, True),
 (True, True, False),
 (True, True, True)]
wim
  • 338,267
  • 99
  • 616
  • 750