[SciPy-user] Finding all combinations of numbers

Alan G Isaac aisaac@american....
Sun Jan 13 08:44:40 CST 2008


Here's a powerset creator that should work for any iterable.
It is easily changed to a generator, which might be wise
if your iterables are of any length.

def subsets(s):
    result = list( [] )
    for xi in s:
        result += list( subset+[xi] for subset in result )
    return result

Cheers,
Alan Isaac




More information about the SciPy-user mailing list