{"record":{"id":"14ecf3d1acf4d0b8","repo":"TheAlgorithms/Python","slug":"all-elements-must-be-integers","errorCode":null,"errorMessage":"all elements must be integers","messagePattern":"all elements must be integers","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/find_unique_number.py","lineNumber":26,"sourceCode":"    >>> find_unique_number([4, 5, 4, 6, 6])\n    5\n    >>> find_unique_number([7])\n    7\n    >>> find_unique_number([10, 20, 10])\n    20\n    >>> find_unique_number([])\n    Traceback (most recent call last):\n        ...\n    ValueError: input list must not be empty\n    >>> find_unique_number([1, 'a', 1])\n    Traceback (most recent call last):\n        ...\n    TypeError: all elements must be integers\n    \"\"\"\n    if not arr:\n        raise ValueError(\"input list must not be empty\")\n    if not all(isinstance(x, int) for x in arr):\n        raise TypeError(\"all elements must be integers\")\n\n    result = 0\n    for num in arr:\n        result ^= num\n    return result\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":8,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/find_unique_number.py#L8-L38","documentation":"Raised by find_unique_number when any element of the list is not an int. The XOR fold requires homogeneous integers; mixing types would raise a confusing operand TypeError deep in the loop, so the function validates all elements up front. Note: bools pass because isinstance(True, int) is True.","triggerScenarios":"Calling find_unique_number([1, 'a', 1]) or any list containing floats/strings/None among the ints.","commonSituations":"Lists built from mixed parsing (some fields ints, some strings), JSON arrays with heterogeneous numbers, or flags/None leaking into numeric data.","solutions":["Coerce elements: find_unique_number([int(x) for x in arr]) when all items are numeric.","Filter or fix the data source so the list contains only integers.","Add an explicit element-type check where the data enters your program, not where the algorithm runs."],"exampleFix":"# before\nfind_unique_number([1, 'a', 1])  # TypeError\n\n# after\nfind_unique_number([int(x) for x in ['1', '1', '20']])  # 20","handlingStrategy":"type-guard","validationCode":"if not all(isinstance(x, int) and not isinstance(x, bool) for x in arr):\n    raise TypeError(\"all elements must be integers\")","typeGuard":"def all_ints(arr: list) -> bool:\n    return all(isinstance(x, int) for x in arr)","tryCatchPattern":"try:\n    unique = find_unique_number(arr)\nexcept TypeError:\n    unique = find_unique_number([int(x) for x in arr])","preventionTips":["Coerce heterogeneous numeric lists with [int(x) for x in arr] first.","Reject mixed-type arrays at the parse/ingest layer.","Remember bool counts as int — filter flags out explicitly when undesired."],"tags":["bit-manipulation","type-validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}