2

I am trying to list out all the possible combinations of groups of 3 that one can make of 6 people. (A, B, C, D, E, F)

  • The order doesn't of the group doesn't matter
  • The order of the pair doesn't matter

Possible combinations:

{(B,D),(C,E),(G,H)}

{(B,C),(D,E),(G,H)}

{(B,E),(C,D),(G,H)}

I could only get as far to write:

from itertools import combinations
x = combinations('ABCDEF', 2)
z = [y for y in x]

I have no idea on how I should create combinations out of combinations, the docs is not to much help. I think I have to someone create an algorithm from scratch.

  • I know that there should be 15 total combinations to list
MarianD
  • 13,096
  • 12
  • 42
  • 54
purrp son
  • 51
  • 5

1 Answers1

0

You can implement this as a backtracking problem. First, you need to find all the permutations. After that, you should slice the lists. For example: first permutation is [A,B,C,D,E,F]. You will slice it like this[(A,B),(C,D),(E,F)], second permutation will be [A,B,C,D,F,E] and slice is [(A,B),(C,D),(F,E)]. And so on.

cristian hantig
  • 1,110
  • 1
  • 12
  • 16