0

So, say that I have a list of 250 distinct numbers. For task 1, I want to get all pairwise combinations (e.g. 1 & 2, 1 & 3, 1 & 4, 1 & 5....). And then output these in a list such as [1 2 1 3 1 4....] **P.S. if i include 1 & 2, I would not want to include 2 & 1 (same thing in this case).

For task 2, I want to do the same as above but now all triple combinations (e.g. 1 & 2 & 3, 1 & 2 & 4, 1 & 2 & 5, etc.....)

Then for task 3, I want to do quadruple combinations, and so on.

Is there a way to do this so that the only thing I would have to change for the function is the # of numbers per combination (e.g pair, triple, quadruple, etc.)?

Thanks.

srv_77
  • 547
  • 1
  • 8
  • 20
  • 1
    Yes, `itertools.combinations` can do that, but do you understand that it is a collection larger than the size of the universe? At the 4 level, there are already 3 billion combinations. The 5 level has almost a trillion. – Tim Roberts Dec 02 '21 at 04:58
  • 1
    The duplicate question is literally [the first result that comes up on Google](https://www.google.com/search?q=How+to+get+all+possible+N+number+of+combinations+of+250+numbers+in+a+list%3F+(python)) when the title of your question is searched for. – Selcuk Dec 02 '21 at 04:59

0 Answers0