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
itertools
really is the way to go as has been pointed out by everyone. But if you really want to see the nuts and bolts of the algorithm required for this, you should look up recursive descent. Here's how it would work in your case:
def tablize(n, truths=[]):
if not n:
print truths
else:
for i in [True, False]:
tablize(n-1, truths+[i])
Tested, working
Hope this helps