Truthtable Script

A small python script to create a truthtable.

Update: name, you are a God.

#!/usr/bin/env python

import itertools

def truthtable(fields=2, elements=(True, False)):
    '''Create a truthtable'''
    liste = []
    for element in elements:
        for i in xrange(fields):
            liste.append(element)

    perm = itertools.permutations(liste, fields)
    nodup = tuple(set(perm))
    sor = sorted(nodup)
    return sor
    return tuple(itertools.product(elements, repeat=fields))

f = lambda x, y: x and y

for i in truthtable(2):
    for element in i:
        print str(element).center(8) + ' ',
    print f(*i)
Truthtable Script