I want to do a comparison between every pair of elements in the list without the following: DIFFERENCE=[1,2,3,4,5,6]
- no self comparisons
- no reverse comparisons
So the answer will be [1,2],[1,3],[1,4],[1,5],[1,6],[2,3],[4,5],[5,6],[3,4],[2,4],[2,5],[3,6],[2,6],[3,5],[4,6] I have written this so far but I was looking for a faster way.
for i in DIFFERENCE:
for j in DIFFERENCE:
if(some condition and i!=j and i+'_'+j not in COMPARISON and j+'_'+i not in COMPARISON):
COMPARISON.append(i+'_'+j);
COMPARISON.append(j+'_'+i);
ANS_COUNT=ANS_COUNT+1;