0

So i am doing a comb. auction algorithm and i like to give him N number of items for example

(A,B,C)

and i want the algorithm to give me back the following result

(A,B,C)
(ABC)
(AB,C)
(AC,B)
(BC,A)

any ideas ?

i tried this one but its not enough

k =[1,2,3]
def powerset(xs):
    result = [[]]
    for x in xs:
        subsets = [subset + [x]  for subset in result]
        result.extend(subsets)
    return result
print (powerset(k))

1 Answers1

0

This is a partitioning problem that requires recursion. It has been answered here: Set partitions in Python

examiner
  • 156
  • 6