Three properties of XOR make a small piece of magic together: a number XORed with itself is 0 (x ^ x == 0), XORed with 0 it is itself (x ^ 0 == x), and order does not matter. So if you XOR a pile of numbers together, everything that appears an even number of times cancels out; what is left is what appears an odd number of times.
odd_one = 0for v in [7, 3, 7, 9, 3]:odd_one ^= v# odd_one is 9
The same idea solves "which one is missing?". XOR together all the numbers from 0 to n and all the numbers in the list: every number in the list has now appeared twice and is gone, and the missing one appeared once and stays. Adding and subtracting does the same job; XOR's advantage is that there is no overflow to worry about however large the numbers get.