0

i have a list of of 53 element each element is a tuple e.g.

list = [(1,1) , (2,2) ,(3,3) ,(4,4) ,(5,5) ,(6,6) ,(7,7) ,(8,8) ,(9,9) ,(10 ,10) , ...(53,53)]

what i wanna do is to create sub-lists that contain 9 elements each of all possible combinations . but the elements in each sub-list must be unique e.g.

[[(1,1) ,(2,2) ,(3,3) ,(29,29) , (35,35) ,(40,40) ,(45,45),(50,50),(52,52)] ,[(2,2) ,(6,6) ,(3,3) ,(9,9) , (20,20) ,(25,25) ,(35,35) ,(40,40),(43,43) ] , [(3,3),(5,5),(7,7) ,(10,10) ,(25,25) ,(35,35) , (40,40),(43,43) ,(45,45)] , ...]

i tried using itertools combinations like shown below :

combination = []
for combo in itertools.combinations(list, 9) :
    combination.append(combo)

but the program keeps crashing . so is there any other way to do it ?

  • Your input and output don't quiet make sense. Do you want all 9 element sublists from your list? How important is order? I don't believe there is a quick easy solution for this. You may have to get down and dirty with with loops most likely. – Error - Syntactical Remorse May 21 '19 at 20:05
  • @Error-SyntacticalRemorse yes i want all 9 element sublists . the order should be from lowest to highest. what i am trying to do is similar to this [https://stackoverflow.com/questions/27974126/how-to-get-all-combinations-of-length-n-in-python] . but when im using whats mentioned in the answer the program crashes . – Alfaisal Albakri May 21 '19 at 22:13
  • It crashes because of the sheer number possible outputs. That code works but there is a few billion combinations. – Error - Syntactical Remorse May 21 '19 at 23:14

0 Answers0