Python 3, today's one-liner
Method 1 - xor\n\nJust xor all the numbers together. You\'ll get the unique number. \n\nUse functools.reduce and operator.xor to do it one line.\n\nTime: O(n)\n
# Method 1 - xor\n\nJust xor all the numbers together. You\'ll get the unique number. \n\nUse [functools.reduce](https://docs.python.org/3/library/functools.html#functools.reduce) and [operator.xor](https://docs.python.org/3/library/operator.html#operator.xor) to do it one line.\n\nTime: `O(n)`\nSpace: `O(1)`\n\n## One line\n\n```python\nclass Solution:\n  def singleNonDuplicate(self, A: List[int]) -> int:\n    return reduce(xor, A)\n```\n\n## True one-liner\n\n```python\nclass Solution: singleNonDuplicate = lambda A: reduce(xor, A)\n```\n\n-----\n# Method 2 - bisect\n\nIt\'s a sorted list, so we should be able to use binary search. Which means we should be able to use [bisect](https://docs.python.org/3/library/bisect.html) somehow. But how?\n\nLet\'s take the numbers and pair every two...\n```\n[1,1,3,3,4,4,7,8,8,9,9]\n...\n[(1,1), (3,3), (4,4), (7,8), (8,9), (9)]\n...\n[ match, match, match, no-match, no-match, single]\n```\nSo let\'s assigning `match` and `no-match` values and chop off the single at the end. If we have `match` be `0` and `no-match` be `1`, the array is sorted and we\'re looking for where the `0`\'s become `1\'s`. If they\'re all 0\'s, then our number is the single one at the end.\n\nWe can use [bisect_left](https://docs.python.org/3/library/bisect.html#bisect.bisect_left) to find the first 1, or [bisect_right](https://docs.python.org/3/library/bisect.html#bisect.bisect_right) to find the last 0. Either works, but you need an extra +1 if you use the position of the last 0.\n\nThen we take the position returned by bisect_left and double it, and that is the index of our answer.\n\nNote that to actually perform this version of the binary search, we have to create a class wrapper to override the [`A[i]` operation](https://docs.python.org/3/reference/datamodel.html#object.__getitem__).\n\nTime: `O(log n)`\nSpace: `O(1)`\n\n## Four lines\n\n```python\nclass Solution:\n  def singleNonDuplicate(self, A: List[int]) -> int:\n    class Wrapper:\n      def __getitem__(self, i):\n        return A[2*i] != A[2*i+1]\n    return A[2*bisect_left(Wrapper(), 1, 0, len(A)//2)]\n```\n\n## True one-liner\n\nUse the [type function](https://docs.python.org/3/library/functions.html#type) instead of defining a `class`.\n\n```python\nclass Solution: singleNonDuplicate = lambda _,A: A[2*bisect_left(type(\'\', (), {\'__getitem__\': lambda _,i: A[2*i] != A[2*i+1]})(), 1, 0, len(A)//2)]\n```
[]