{"record":{"id":"6166e0e9ecfa4e06","repo":"TheAlgorithms/Python","slug":"input-list-must-not-be-empty","errorCode":null,"errorMessage":"input list must not be empty","messagePattern":"input list must not be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/find_unique_number.py","lineNumber":24,"sourceCode":"    >>> find_unique_number([1, 1, 2, 2, 3])\n    3\n    >>> 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":6,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/find_unique_number.py#L6-L38","documentation":"Raised by find_unique_number when the input list is empty. The function finds the element appearing once by XOR-folding the whole list; an empty list has no unique element, so it refuses rather than returning the XOR identity 0.","triggerScenarios":"Calling find_unique_number([]). The check runs before the element-type check, so an empty list of anything raises this, not the TypeError.","commonSituations":"Processing batches/chunks where a filter or group-by produced zero elements; forgetting to handle empty input before reduction-style helpers.","solutions":["Check truthiness at the call site: skip or return None when not arr.","Fix upstream filtering so the 'every element appears twice except one' precondition is actually met before calling.","If empty means 'no answer', return a sentinel explicitly instead of relying on the exception."],"exampleFix":"# before\nunique = find_unique_number(group)  # group can be []\n\n# after\nunique = find_unique_number(group) if group else None","handlingStrategy":"validation","validationCode":"if not arr:\n    return None  # or skip, per your domain\nreturn find_unique_number(arr)","typeGuard":null,"tryCatchPattern":"try:\n    unique = find_unique_number(items)\nexcept ValueError:\n    unique = None  # empty batch has no unique element","preventionTips":["Check truthiness of filtered/grouped lists before reduction helpers.","Handle the empty case explicitly rather than relying on exceptions for control flow.","Ensure upstream filters preserve the pair-plus-one precondition."],"tags":["bit-manipulation","input-validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}