import itertools


def powerset(iterable):
    """Calculates the powerset of a set (e.g. [1,2] --> [[],[1],[2],[1,2]])."""
    s = list(iterable)
    return itertools.chain.from_iterable(
        itertools.combinations(s, r) for r in range(len(s) + 1))