1

I have a list , guys = range(1,21) and have gotten the unique combination of pairs using

itertools.combinations(guys,2)

I'm looking to create 19 sets using these subset pairs such that each value is listed only once in each set.

For example, the first set would be:

(1,2),(3,4),(5,6),(7,8),(9,10),(11,12),(13,14),(15,16),(17,18),(19,20)

And the following 18 sets would be similar, a unique set with 10 of these combination pairs where each number is only used once.

For example, if this were for range(4), the total answer would be:

[(0,1),(2,3)], [(0,2),(1,3)], [(0,3),(1,2)]

I don't really even know where to begin.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
  • So you want to generate the set of partitions into pairs of some set (in this case a range from 1..21)? – castle-bravo Mar 21 '18 at 01:53
  • "… such that each value is listed only once in each set." In a **set** all item are listed only once. – Klaus D. Mar 21 '18 at 01:54
  • Right, my wording was wrong. I meant, for example, the set (4,5) and (4,10) wouldn't be in the same set. The two are unique sets, but both include 4. – KyrazzleDazzle Mar 21 '18 at 01:58
  • @KlausD. In this case I think he means a set of pairs, i.e. some subset of the power set. – castle-bravo Mar 21 '18 at 01:58
  • Can you set yourself a simpler problem to start? Suppose you had range(4): [0,1,2,3], and you wanted all of these sets of pairs. How many such sets are there? Can you do it on paper? How would you do it with range(5)? – castle-bravo Mar 21 '18 at 02:00
  • Right, so using range(4), I'd have: [(0,1),(2,3)], [(0,2),(1,3)], [(0,3),(1,2)]. @castle-bravo, I know you meant that as a hint/starting point. I'm just also including what I'm looking for as a means to explain my question a little better. – KyrazzleDazzle Mar 21 '18 at 02:04
  • What about [(1,0), (3,2)]? – castle-bravo Mar 21 '18 at 02:06
  • well no, because that would be the same as the first one. I am just looking for the combinations of each, not the permutations. – KyrazzleDazzle Mar 21 '18 at 02:08
  • Okay, so given N numbers, how many ways are there to select a single pair from those N numbers? – castle-bravo Mar 21 '18 at 02:09
  • I think there is a [duplicate question](https://stackoverflow.com/questions/374626/how-can-i-find-all-the-subsets-of-a-set-with-exactly-n-elements). – Sohaib Farooqi Mar 21 '18 at 02:17
  • Yes, that may what I'm looking for – KyrazzleDazzle Mar 21 '18 at 02:19

0 Answers0