Skip to content

Instantly share code, notes, and snippets.

@wcarss
Created August 23, 2011 19:43
Show Gist options
  • Save wcarss/1166285 to your computer and use it in GitHub Desktop.
Save wcarss/1166285 to your computer and use it in GitHub Desktop.
subset generator
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
@wcarss
Copy link
Author

wcarss commented Aug 23, 2011

slightly improved to deal with any non-iterable object as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment