I'm trying to write a nested loop that prints out all possible "unique pairs" of numbers from a certain range. For example, if the range was from 1 to 3 the unique pairs would be:
(1,2) (1,3) (2,3)
If the range was from 1 to 4 the unique pairs would be:
(1,2) (1,3) (1,4) (2,3) (2,4) (3,4)
Here's how I did it for 1 to 3:
for i in range(1,4):
for j in range(2,4):
if (i != j & j != (i-1)):
print (i,j)
which prints out (1, 2), (1, 3),(2, 3). But this is a hack because it doesn't work when I change the range to 1,5. It prints out duplicate pairs such as (1,5) and (5,1).