Created
August 23, 2011 19:43
-
-
Save wcarss/1166285 to your computer and use it in GitHub Desktop.
subset generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def all_subsets(*args): | |
from collections import Iterable | |
from itertools import permutations as permute | |
if len(args) == 1: | |
if not isinstance(args[0], Iterable): | |
args = [args[0]] | |
else: | |
args = args[0] | |
output = [] | |
for i in permute(args): | |
output.append(i) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
slightly improved to deal with any non-iterable object as well