{"record":{"id":"682b3e55a70a70d0","repo":"TheAlgorithms/Python","slug":"find-min-iterative-arg-is-an-empty-sequence","errorCode":null,"errorMessage":"find_min_iterative() arg is an empty sequence","messagePattern":"find_min_iterative\\(\\) arg is an empty sequence","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/find_min.py","lineNumber":24,"sourceCode":"    Find Minimum Number in a List\n    :param nums: contains elements\n    :return: min number in list\n\n    >>> for nums in ([3, 2, 1], [-3, -2, -1], [3, -3, 0], [3.0, 3.1, 2.9]):\n    ...     find_min_iterative(nums) == min(nums)\n    True\n    True\n    True\n    True\n    >>> find_min_iterative([0, 1, 2, 3, 4, 5, -3, 24, -56])\n    -56\n    >>> find_min_iterative([])\n    Traceback (most recent call last):\n        ...\n    ValueError: find_min_iterative() arg is an empty sequence\n    \"\"\"\n    if len(nums) == 0:\n        raise ValueError(\"find_min_iterative() arg is an empty sequence\")\n    min_num = nums[0]\n    for num in nums:\n        min_num = min(min_num, num)\n    return min_num\n\n\n# Divide and Conquer algorithm\ndef find_min_recursive(nums: list[int | float], left: int, right: int) -> int | float:\n    \"\"\"\n    find min value in list\n    :param nums: contains elements\n    :param left: index of first element\n    :param right: index of last element\n    :return: min in nums\n\n    >>> for nums in ([3, 2, 1], [-3, -2, -1], [3, -3, 0], [3.0, 3.1, 2.9]):\n    ...     find_min_recursive(nums, 0, len(nums) - 1) == min(nums)\n    True","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/find_min.py#L6-L42","documentation":"Raised by find_min_iterative() in maths/find_min.py when nums is an empty sequence. The minimum of zero elements does not exist; the function seeds min_num = nums[0] and would otherwise crash, so it raises ValueError up front — same contract as built-in min().","triggerScenarios":"Calling find_min_iterative([]) (per its doctest). The `if len(nums) == 0` guard raises before nums[0] is accessed.","commonSituations":"Aggregating over empty query results, empty sensor batches, or config-driven lists that were never populated; iterating paginated APIs where a page comes back empty.","solutions":["Check `if not nums:` before calling and supply a default or raise a domain error.","Use built-in min(nums, default=...) if you want empty-input tolerance.","Validate collection size where the data enters your program."],"exampleFix":"# before\nlow = find_min_iterative(readings)  # readings == [] -> ValueError\n\n# after\nlow = find_min_iterative(readings) if readings else 0.0","handlingStrategy":"validation","validationCode":"if not nums:\n    raise ValueError('cannot compute min of empty input')\nlow = find_min_iterative(nums)","typeGuard":"def is_nonempty_seq(nums: object) -> bool:\n    return hasattr(nums, '__len__') and len(nums) > 0","tryCatchPattern":null,"preventionTips":["Handle empty batches/pages explicitly before aggregating.","Use min(nums, default=...) when a default is acceptable.","Add empty-input unit tests for aggregation code paths."],"tags":["math","min","empty-sequence","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}