# List of partitions of size $k$ elements of a set [duplicate]

I have a list of distinct elements of even length, $\{a_{1},\dots,a_{2n}\}$, for some $n\geq1$, and I want to generate a new list from it that contains lists of subsets of length two. The criteria are that ordering does not matter, and that no single element of the original list can appear twice in the same element of the new list.

Let me try to illustrate what I want with an example. Suppose I start with

listInt={a1,a2,a3,a4};


I want to generate the list {{{a1,a2},{a3,a4}},{{a1,a3},{a2,a4}},{{a1,a4},{a2,a3}}}. I can do this with

listPairs={};
twoSubsets = Subsets[listInt, {2}];
For[i=1, i<=Length[twoSubsets], i++,
AppendTo[listPairs, Sort[{twoSubsets[[i]], DeleteCases[listInt, Alternatives@@twoSubsets[[i]]]}]]
];
listFinal = Union[listPairs]


but I suspect that this is by far not the best solution. More importantly, it cannot be extended straightforwardly to a starting list of length higher than four.

What code can achieve what I need for a starting list of any even length?

-
Put concisely, you are looking to partition a set into sets of size two. Is this correct? Use of the word "partition", especially in the title, would make this question much clearer. –  Szabolcs Feb 13 at 17:06
@Szabolcs Partitioning the list with the specified criteria is exactly what I want. Thanks for the suggestion, I updated the title. –  AndyS Feb 13 at 17:09
I clarified your title a bit more to make it obvious that the SetPartitions function from Combinatorica doesn't already do what you are asking for. –  Szabolcs Feb 13 at 17:22
Isn't it a duplicate of: Partition a set into subsets of size k ? –  Kuba Feb 13 at 18:13
@Kuba Thank you, and sorry for the duplicate entry. I did not see that question. –  AndyS Feb 13 at 18:24

## marked as duplicate by Kuba, belisarius, rm -rf♦Feb 13 at 18:55

The built-in function Subsets will do it:
     listInt={a1,a2,a3,a4};