I'm wanting to write a Python script that provides all possible combinations of some variables and arguments but to always include all variables in the results.
I've tried a few attempts but the closest I can get is literally all combinations. For example, let's say a, b, c, d and e can either be true or false. I want all possible combinations but importantly I'm trying to include all of those variables each time. So the following two examples are valid among the results: a:true, b:false, c:false, d:false, e:false a:true, b:true, c:false, d:false, e:false (note b is different)
But the following is NOT what I'm looking for: a:true, c:false
I want all possible combinations but always including a-e.
There is an answer already provided by Martijn Pieters, which is basically what I want minus the requirement that all variables are represented (Find all possible combinations of arguments in Python). Here is the code by Pieters:
from itertools import product
for combo in product((None, True, False), repeat=3):
arguments = {k: v for k, v in zip('abc', combo) if v is not None}
print arguments
>>> from itertools import product
>>> for combo in product((None, True, False), repeat=3):
... arguments = {k: v for k, v in zip('abc', combo) if v is not None}
... print arguments
...
{}
{'c': True}
{'c': False}
{'b': True}
{'c': True, 'b': True}
{'c': False, 'b': True}
{'b': False}
{'c': True, 'b': False}
{'c': False, 'b': False}
{'a': True}
{'a': True, 'c': True}
{'a': True, 'c': False}
{'a': True, 'b': True}
{'a': True, 'c': True, 'b': True}
{'a': True, 'c': False, 'b': True}
{'a': True, 'b': False}
{'a': True, 'c': True, 'b': False}
{'a': True, 'c': False, 'b': False}
{'a': False}
{'a': False, 'c': True}
{'a': False, 'c': False}
{'a': False, 'b': True}
{'a': False, 'c': True, 'b': True}
{'a': False, 'c': False, 'b': True}
{'a': False, 'b': False}
{'a': False, 'c': True, 'b': False}
{'a': False, 'c': False, 'b': False}
'''
Ignoring the None option this is almost exactly what I've been trying to do but in this example I wouldn't want to just return that a is false. I would want it to return far fewer combinations because a, b, and c should always be included. It's just the combination of whether they're true or false I want to get from this.
What would be the best way to modify this example to achieve the correct results? Or do you recommend a completely different approach? Many thanks.