consider
a = [1,2,3,4]
i = 0
j = 1
for i in range(len(a)):
for j in range(len(a)):
d = (a[i]-a[j])
j = j + 1
print i, j, d
i = i + 1
Output
0 1 0
0 2 -1
0 3 -2
0 4 -3
1 1 1
1 2 0
1 3 -1
1 4 -2
2 1 2
2 2 1
2 3 0
2 4 -1
3 1 3
3 2 2
3 3 1
3 4 0
I am trying to iterate through my array so that I can only get numbers that are non-zero for d and that I do not go over the same i and j (ex: if i = 0,j=1 or i=1, j=0). Its just like doing a combination problem for which I am looking the number of pairs in my array and the d that goes for it.
i=0andj=0doesn't do anything. Iterating through thefor i in range(len(a))starts outias 0. And iteratingfor j in range(len(a))startsjas 0. To iterate fromj=1tolen(a), do:for j in range(1, len(a)).