a = [5,7,3,1,2]
for i in a:
for j in a:
if(i==j):
continue
else:
print(i,j)
print("")
output:
5 7
5 3
5 1
5 2
7 5
7 3
7 1
7 2
3 5
3 7
3 1
3 2
1 5
1 7
1 3
1 2
2 5
2 7
2 3
2 1
My code just displays all the values but will skip the values which matches but if I want dont want to display values which are printed already like if value (5,7) is printed it should not print again as (7,5). Once value 5 7 is printed so for next iteration it should not display 7 5 and this should happen with all values in array. Please someone help me. Thank you. If there is duplication of question please guide me to that question.