My question is simple: \"how to build a dynamic growing truth table in python in an elegant way?\"
for n=3
for p in False, True:
for q in False, Tru
returning a datastructure representing the table is fine
...in that case range(2 ** n)
is all you need. Each number in the range represents a row in the truth table. The i
th bit of the binary representation of the number k
is 1 if and only if the i
th variable is true in the k
th row of the table.
If you want an actual table you can use:
[ [ ((row >> bit_index) & 1) == 1 for bit_index in range(n)]
for bit_index in range(2 ** n) ]