Question: I am trying to create a list of integers and then scan it in order to find the minimum absolute value of the substractions of the elements of the list. I have created the list, but there is problem in the code which finds the minimum absolute value, as the result it shows is not correct. I think it is probably in the possitions of the elements of the list during the loops. Can you help me find it?

For example, when I create a list `Α = [2, 7, 5, 9, 3, 1, 2]`, the result of `min` should be 0, but it is 1.

Here is my code:

```
min=1000
for i in range (1, N-1):
    for j in range (i+1, N):
        if (abs (A [i-1] - A [j-1])<min):
            min = abs (A [i-1] - A [j-1])
print ("%d" %min)

```

Answer: 
You should not be subtracting 1 from j in the inner loop as you end up skipping the comparison of the last `2`. It is better to make the adjustments in the loop ranges, rather than subtracting 1 (or not) in the loop code:

```
A = [2, 7, 5, 9, 3, 1, 2]

N = 7

mint = 1000

for i in range (0, N-1):
    for j in range (i+1, N):
        if (abs(A[i] - A[j]) < mint):
            mint = abs(A[i] - A[j])
            print(i, j)
            print(mint)
print(mint) # 0

```

I have also avoided the use of a built-in function name `min`.

---

To avoid the arbitrary, magic, number 1000, you can perform an initial check against `None`:

```
A = [2, 7, 5, 9, 3, 1, 2]

N = 7

mint = None

for i in range (0, N-1):
    for j in range (i+1, N):
        if mint is None:
            mint = abs(A[i] - A[j])
        elif (abs(A[i] - A[j]) < mint):
            mint = abs(A[i] - A[j])
            print(i, j)
            print(mint)
print(mint) # 0

```
This is what you are looking for:

```
A = [2, 7, 5, 9, 3, 1, 2]

diffs = []
for index1, i in enumerate(A):
     for index2, j in enumerate(A):
         if index1 != index2:
             diffs.append(abs(i-j))             

print(min(diffs))

```

Output:

```
0

```

**Updated** to exclude subtraction of same items