[SciPy-user] Finding all combinations of numbers

Andrew Straw strawman@astraw....
Sun Jan 13 00:34:38 CST 2008


In addition to what David Warde-Farley said, I also have this lurking in
my code base:

def setOfSubsets(L):
    """find all subsets of L

    from Alex Martelli:
    http://mail.python.org/pipermail/python-list/2001-January/067815.html
    """
    N = len(L)
    return [ [ L[i] for i in range(N)
                if X & (1L<<i) ]
        for X in range(2**N) ]



More information about the SciPy-user mailing list