Question: given these two lists

```
l1=[0,0,0,0,1,1,1,1]
l2=[0,0,0,1,1,1,1,1]

```

they are identical except for the 4th element. I need a code that detects the difference between these two sets and prints out the location of the detected difference. In this case it would be = 4.
The `intersection` and `union` command wouldn't work as they don't take the index into consideration.

I have tried this code, but it does not print out anything:

```
l1=[0,0,0,0,1,1,1,1]
l2=[0,0,0,1,1,1,1,1]

for i in l1:
    if i != l2[l1.index(i)]:
        print(l1.index(i),i)

```

Answer: 
Your code does not work because `list.index(value [, pos])` only reports **the *first* occurence** of a value in that list [after `pos`].

This would report the differences:

```
l1=[0,0,0,0,1,1,1,1]
l2=[0,0,0,1,1,1,1,1]
print(*(p for p,v in enumerate(zip(l1,l2)) if v[0]^v[1]))

```

Output:

```
3

```

The `zip(..)` pairs up values positionally in to tuples, `enumerate(..)` gets the `index, tuple` value and `v[0]^v[1]` is a logical xor that is only true if the values differ at least in 1 bit.

See:

* [enumerate](https://docs.python.org/3/library/functions.html#enumerate)
* [zip](https://docs.python.org/3/library/functions.html#zip)
* [binary bitwise ops (including xor)](https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations)

---

The simpler version of this works without zip:

```
for index,number in enumerate(l1): # get index & number of one list
    if l2[index] != number:        # compare to other number
        print(f"On {index}: {number} != {l2[index]}")

```
You can use zip

```
l1=[0,0,0,0,1,1,1,1]
l2=[0,0,0,1,1,1,1,1]

diff_idx = [idx for idx,(x,y) in enumerate(zip(l1,l2)) if x != y]
print(diff_idx)

```

output

```
[3]

```