# Separate list elements into groups of two in all possible ways? [duplicate]

Consider a list with an even number of elements, e.g.

list = {1,2,3,4};


I would like to have a function fun that produces all possible ways the elements could be arranged in unordered groups of two, so that for example

fun[list]


{ {{1,2},{3,4}} , {{1,3},{2,4}} , {{1,4},{2,3}} }

While for the example of length 4 above the decomposition is kind of trivial, for longer examples it becomes more cumbersome. Is there a way to do this efficiently in Mathematica?

DeleteDuplicates[
Sort[
(Sort /@ Partition[#, 2] & /@ Permutations[list, {Length[list]}])]
]

• This produces way too many elements. But the answer to the question linked by Carl Woll seems to do the trick. – Kagaratsch Mar 28 '18 at 23:06