Given a set of numbers, say, {A,B,C,D,E}
, I wish to generate the set partitions like:
{A}, {B}, {C}, {D}, {E}
{A,B}, {C}, {D}, {E}
{A,B}, {C,D}, {E}
{A,B,E}, {C,D}
{A,B}, {C,D,E} # etc.
Is there some Pythonic way to do this?
Edit1: Note that I have removed one of the original set that I had included - {{A,B,C,D,E}}
. I want to generates sets of a maximum size of 3
. Then how do I achieve this?
Edit2: This is not a duplicate because the marked question is pretty different. I have an upper limit of a size of 3
.