Reputation: 331
input:
vv = [True, False, None, True, None]
Is there a way to generate truth table by replacing undefined one boolean at a time So the ouptut would be
[True, False, True, True, None]
[True, False, False, True, None]
[True, False, None, True, False]
[True, False, None, True, True]
Upvotes: 2
Views: 360
Reputation: 238199
Assuming that Undefined can be None, for example, you could do as follows:
l = [True, False, None, True, None]
# first get indices of None/Undefined elements in the input list
indexes = [i for i,v in enumerate(l) if v is None]
# for each index, generate new list using True and False
# as substitutes.
for idx in indexes:
for sub in [True, False]:
new_l = l[:]
new_l[idx] = sub
print(new_l)
This gives:
[True, False, True, True, None]
[True, False, False, True, None]
[True, False, None, True, True]
[True, False, None, True, False]
Upvotes: 2