I believe this is essentially the same method as the
itertools.combinations function, but is there any way to make this code more more perfect in terms of speed, code size and readability :
def all_subsets(source,size): index = len(source) index_sets = [()] for sz in xrange(size): next_list =  for s in index_sets: si = s[len(s)-1] if len(s) > 0 else -1 next_list += [s+(i,) for i in xrange(si+1,index)] index_sets = next_list subsets =  for index_set in index_sets: rev = [source[i] for i in index_set] subsets.append(rev) return subsets
>>> Apriori.all_subsets(['c','r','i','s'],2) [['c', 'r'], ['c', 'i'], ['c', 's'], ['r', 'i'], ['r', 's'], ['i', 's']]
There is probably a way to use generators or functional concepts, hopefully someone can suggest improvements.