# How to make two sub-sets each with two distinct elements having a list with four elements?

Consider the following list:

list = {{meson1, p1}, {meson2, p2}, {meson3, p3}, {meson4, p4}}


I would like to organize it into two sub-sets, each with two elements, with no repetitions. Say,

listfinal = {{{{meson1,p1},{meson2,p2}},{{meson3,p3},{meson4,p4}}}, {{{meson1,p1},{meson3,p3}},{{meson2,p2},{meson4,p4}}}, ...}


where we have, e.g., the following first pair of 2-subsets:

{{{meson1,p1},{meson2,p2}},{{meson3,p3},{meson4,p4}}}


The subset {{meson4,p4},{meson2,p2}} is a duplicate of {{meson2,p2},{meson4,p4}}.

I know that there is a command

Subsets[list, {2}]


but it does not do exactly what I want: one more action is missing - I need to combine the elements of the 2-subsets such that I will get listfinal. Could you please tell me how to obtain listfinal?

P.S. In my real example, meson1, meson2, etc (but not p1,...), are strings, and it may be that "meson2" is the same as "meson1".

For the case in question only:

({#,Complement[list, #]}&/@Subsets[#, {2},3)&@list

(* {
{{{meson1, p1}, {meson2, p2}}, {{meson3, p3}, {meson4, p4}}},
{{{meson1, p1}, {meson3, p3}}, {{meson2, p2}, {meson4, p4}}},
{{{meson1, p1}, {meson4, p4}}, {{meson2, p2}, {meson3, p3}}}
} *)


Or

({#,Complement[list, #]}&/@Subsets[#, {2},Binomial[Length@#,2]/2])&@list

(* {
{{{meson1, p1}, {meson2, p2}}, {{meson3, p3}, {meson4, p4}}},
{{{meson1, p1}, {meson3, p3}}, {{meson2, p2}, {meson4, p4}}},
{{{meson1, p1}, {meson4, p4}}, {{meson2, p2}, {meson3, p3}}}
} *)

({#,Complement[Range[4], #]}&/@Subsets[#,{2},Binomial[Length@#,2]/2])&@Range[4]

(* {
{{1, 2}, {3, 4}},
{{1, 3}, {2, 4}},
{{1, 4}, {2, 3}}
} *)

Needs["Combinatorica"]

list = {{"meson1", p1}, {"meson2", p2}, {"meson3", p3}, {"meson4",
p4}};

Cases[KSetPartitions[list, 2], {Repeated[{_, _}, {2}]}]


{{{{"meson1", p1}, {"meson2", p2}}, {{"meson3", p3}, {"meson4", p4}}}, {{{"meson1", p1}, {"meson4", p4}}, {{"meson2", p2}, {"meson3", p3}}}, {{{"meson1", p1}, {"meson3", p3}}, {{"meson2", p2}, {"meson4", p4}}}}

Using SubsetCases (new in 12.1)

sub = Transpose @ Partition[SubsetCases[list, {_, _}, Overlaps -> True], 3]


{{{{meson1, p1}, {meson2, p2}}, {{meson2, p2}, {meson3, p3}}},
{{{meson1, p1}, {meson3, p3}}, {{meson2, p2}, {meson4, p4}}},
{{{meson1, p1}, {meson4, p4}}, {{meson3, p3}, {meson4, p4}}}}

The ordering of the right block is slightly different from the accepted result. If this is a problem we could do:

Transpose[{sub[[All, 1]], Reverse @ sub[[All, 2]]}]
`

{{{{meson1, p1}, {meson2, p2}}, {{meson3, p3}, {meson4, p4}}},
{{{meson1, p1}, {meson3, p3}}, {{meson2, p2}, {meson4, p4}}},
{{{meson1, p1}, {meson4, p4}}, {{meson2, p2}, {meson3, p3}}}}