I am trying to build a loop in which random pairs are generated given a list. Essentially, I want to create all combinations of random pairs using a loop without replacement. This is the logic with context:
import numpy as np
x=['apple','cherry','peach','banana']
count=len(x)
interaction=int(count-1) #possible count of matches for a given fruit
matched=[]
for i in range(interaction):
pairs=np.random.choice(x, size=(int(count/2), 2), replace=False)
matched.append(f'Run Number: {i+1}')
matched.append(pairs.tolist())
print(matched)
['Run Number: 1', [['cherry', 'peach'], ['banana', 'apple']], 'Run Number: 2', [['banana', 'peach'], ['apple', 'cherry']], 'Run Number: 3', [['peach', 'cherry'], ['banana', 'apple']]]
The problem is that I want to restrict generating the same pairs. For example, in Run Number 1: we have the 'cherry', 'peach' pair. However, in Run Number 3, we have again 'peach', 'cherry' pair which is the same just inversed.
How can the subsequent iteration take into account the previous pairs saved in the matched list to generate new pairs based on what values are left over?