{"record":{"id":"a2423df6c872da7d","repo":"TheAlgorithms/Python","slug":"the-parameter-days-should-be-a-list-of-integers","errorCode":null,"errorMessage":"The parameter days should be a list of integers","messagePattern":"The parameter days should be a list of integers","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/minimum_tickets_cost.py","lineNumber":93,"sourceCode":"    >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n\n    >>> mincost_tickets([], [])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n\n    >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [1, 2, 3, 4])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n    \"\"\"\n\n    # Validation\n    if not isinstance(days, list) or not all(isinstance(day, int) for day in days):\n        raise ValueError(\"The parameter days should be a list of integers\")\n\n    if len(costs) != 3 or not all(isinstance(cost, int) for cost in costs):\n        raise ValueError(\"The parameter costs should be a list of three integers\")\n\n    if len(days) == 0:\n        return 0\n\n    if min(days) <= 0:\n        raise ValueError(\"All days elements should be greater than 0\")\n\n    if max(days) >= 366:\n        raise ValueError(\"All days elements should be less than 366\")\n\n    days_set = set(days)\n\n    @functools.cache\n    def dynamic_programming(index: int) -> int:\n        if index > 365:","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/minimum_tickets_cost.py#L75-L111","documentation":"Raised as ValueError by mincost_tickets(days, costs) when days is not a list or any element is not an int (isinstance(days, list) and all(isinstance(day, int) ...)). The function models the LeetCode 'minimum cost for tickets' problem over days 1..365, so days must be a list of integers. It is the first of four validation checks, followed by costs shape, empty days (returns 0), and the 1..365 range checks.","triggerScenarios":"mincost_tickets((1,2,3), [1,2,3]) with a tuple instead of a list; mincost_tickets(['1','2'], [1,2,3]) with string days; mincost_tickets([1.0, 2.0], [1,2,3]) with floats; numpy arrays also fail the isinstance(days, list) check.","commonSituations":"Travel dates parsed from CSV/JSON as strings or floats; tuples from config or function returns; numpy date ordinals from pandas pipelines.","solutions":["Normalize before calling: mincost_tickets([int(d) for d in days], costs).","Convert tuples/arrays to list: list(days) / days.tolist().","Validate at ingestion that every day is an int within 1..365, since later checks enforce that range anyway."],"exampleFix":"# before\ncost = mincost_tickets(days, [2, 7, 15])  # days = ['1', '4', '5'] -> ValueError\n\n# after\ncost = mincost_tickets([int(d) for d in days], [2, 7, 15])","handlingStrategy":"type-guard","validationCode":"days = [int(d) for d in days] if not isinstance(days, list) or not all(isinstance(d, int) for d in days) else days\ncost = mincost_tickets(days, costs)","typeGuard":"def is_int_day_list(days: object) -> bool:\n    return isinstance(days, list) and all(\n        isinstance(d, int) and not isinstance(d, bool) for d in days\n    )","tryCatchPattern":"try:\n    cost = mincost_tickets(days, costs)\nexcept ValueError as exc:\n    if 'days should be a list' in str(exc):\n        cost = mincost_tickets([int(d) for d in days], costs)\n    else:\n        raise","preventionTips":["Normalize parsed dates to list[int] (day-of-year 1..365) at ingestion.","Convert tuples and numpy arrays to list before calling strict list-checking APIs.","Validate the full 1..365 domain up front — later checks enforce it with separate errors."],"tags":["python","input-validation","type-error","dynamic-programming"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}