Consider a list of n items = ['a', 'b', 'c', ... n]
Each item can take a boolean state, i.e. True or False. Represented as a list [True, False]
How can I generate a list of lists of all the combinations of states.
For the example of
items = ['a', 'b', 'c']
states = [True, False]
The desired output would be
[pre][[('a', True), ('b', True), ('c', True)],
[('a', True), ('b', True), ('c', False)],
[('a', True), ('b', False), ('c', True)],
[('a', True), ('b', False), ('c', False)],
[('a', False), ('b', True), ('c', True)],
[('a', False), ('b', True), ('c', False)],
[('a', False), ('b', False), ('c', True)],
[('a', False), ('b', False), ('c', False)]][/pre]
Brute force looping could be done, but it seems there must be some Pythonic comprehension, possibly involving itertools. But I can't figure one out (because I'm not very good at Python yet)
Each item can take a boolean state, i.e. True or False. Represented as a list [True, False]
How can I generate a list of lists of all the combinations of states.
For the example of
items = ['a', 'b', 'c']
states = [True, False]
The desired output would be
[pre][[('a', True), ('b', True), ('c', True)],
[('a', True), ('b', True), ('c', False)],
[('a', True), ('b', False), ('c', True)],
[('a', True), ('b', False), ('c', False)],
[('a', False), ('b', True), ('c', True)],
[('a', False), ('b', True), ('c', False)],
[('a', False), ('b', False), ('c', True)],
[('a', False), ('b', False), ('c', False)]][/pre]
Brute force looping could be done, but it seems there must be some Pythonic comprehension, possibly involving itertools. But I can't figure one out (because I'm not very good at Python yet)