reduce def solution(array): xor = reduce(x, y: x ^ y, array, 0) bit = xor & -xor a = reduce(x, y: x ^ y, filter(x: not x & bit, array), 0) b = reduce(x, y: x ^ y, filter(x: x & bit, array), 0) return a, b print(solution([1, 5, 6, 6, 1, 2])) # (2, 5) 5