You are looking for a compact way to write truth tables. (The only other alternative is to find a way to simplify your expressions using Boolean algebra; a simplified form may not exist.) It is impossible to make it simpler than save as you type:
def TruthTable(text): table = {} for line in text.splitlines(): line = line.strip() if line: inputs,output = line.split() table[tuple(bool(int(x)) for x in inputs)] = bool(int(output)) return lambda *inputs:table[inputs]
Demo:
myFunc = TruthTable(''' 000 1 001 0 010 0 011 1 100 1 101 0 110 0 111 1 ''')
Exit:
>>> myFunc(False, False, True) False
If you need more logical outputs, you can adapt this to denote arbitrary expressions using, for example, a dictionary, and post-processing keys in logical tuples:
{ (0,0,0): <expr0>, (0,0,1): <expr1>, (0,1,0): <expr2>, (0,1,1): <expr3>, ... }
You can also do this as follows with binary notation (e.g. 0b110 == 6 ), but I find it much less clean:
{ 0b000: <expr0>, 0b001: <expr1>, ... }
You can even use the list, which you later convert to a dictionary for quick searching (by doing dict((intToBinarytuple(i),expr) for i,expr enumerate(myList)) ):
[ # ABC <expr0>, # 000 <expr1>, # 001 <expr2>, # 010 <expr3>, # 011 ... ]
sidenote . In the unlikely event you will need arbitrary python commands, you can send like this:
conditions = (True, False, True) c = lambda *args: conditions==toBooleanTuple(args) if c(0,0,0): ... elif c(0,0,1): ... elif c(0,1,0): ... elif c(0,1,1): ...