1

I have a list with ten elements, for example:

{x1,x2,x3,x4,x5,x6,x7,x8,x9,x10}

I want to have all the combinations of the 3 elements-list like below:

{{x1,x2,x3},{x1,x2,x4},{x1,x2,x5},.....,{x2,x3,x4},{x2,x3,x5},......}

I cannot find a function to do this.

ZHANG Juenjie
  • 1,121
  • 7
  • 13

1 Answers1

3
lst = {x1, x2, x3, x4, x5};

Subsets[lst, {3}]

{{x1, x2, x3}, {x1, x2, x4}, {x1, x2, x5}, {x1, x3, x4}, {x1, x3, x5}, {x1, x4, x5}, {x2, x3, x4}, {x2, x3, x5}, {x2, x4, x5}, {x3, x4, x5}}

Or, if the order matters,

Permutations[lst, {3}]

Mathematica graphics

kglr
  • 394,356
  • 18
  • 477
  • 896