{"record":{"id":"928ea8bb678ac4c3","repo":"TheAlgorithms/Python","slug":"expected-a-list-of-numbers-as-input-found-type-p","errorCode":null,"errorMessage":"Expected a list of numbers as input, found {type(point).__name__}","messagePattern":"Expected a list of numbers as input, found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"maths/manhattan_distance.py","lineNumber":76,"sourceCode":"         ...\n    TypeError: Expected a list of numbers as input, found int\n    >>> _validate_point(\"not_a_list\")\n    Traceback (most recent call last):\n         ...\n    TypeError: Expected a list of numbers as input, found str\n    \"\"\"\n    if point:\n        if isinstance(point, list):\n            for item in point:\n                if not isinstance(item, (int, float)):\n                    msg = (\n                        \"Expected a list of numbers as input, found \"\n                        f\"{type(item).__name__}\"\n                    )\n                    raise TypeError(msg)\n        else:\n            msg = f\"Expected a list of numbers as input, found {type(point).__name__}\"\n            raise TypeError(msg)\n    else:\n        raise ValueError(\"Missing an input\")\n\n\ndef manhattan_distance_one_liner(point_a: list, point_b: list) -> float:\n    \"\"\"\n    Version with one liner\n\n    >>> manhattan_distance_one_liner([1,1], [2,2])\n    2.0\n    >>> manhattan_distance_one_liner([1.5,1.5], [2,2])\n    1.0\n    >>> manhattan_distance_one_liner([1.5,1.5], [2.5,2])\n    1.5\n    >>> manhattan_distance_one_liner([-3, -3, -3], [0, 0, 0])\n    9.0\n    >>> manhattan_distance_one_liner([1,1], None)\n    Traceback (most recent call last):","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/manhattan_distance.py#L58-L94","documentation":"Raised by _validate_point() in maths/manhattan_distance.py when the point argument itself is not a list (message embeds the actual type name, e.g. 'found tuple'). The validator requires points to be Python lists of numbers; tuples, strings, numpy arrays, and other sequences are rejected even if their contents are numeric.","triggerScenarios":"manhattan_distance((1,2), [1,2]) (tuple point), manhattan_distance('ab', [1,2]) (str), or manhattan_distance(np.array([1,2]), [1,2]) (ndarray).","commonSituations":"Passing tuples from function returns or namedtuple records, numpy arrays from vectorized code, or pandas Series — all common sequence types that are not list.","solutions":["Wrap non-list sequences: manhattan_distance(list(point_a), list(point_b)).","For numpy arrays use .tolist(): manhattan_distance(arr.tolist(), other).","Standardize on lists when constructing the points you will pass to this API."],"exampleFix":"# before\nmanhattan_distance((1, 2), [1, 2])\n\n# after\nmanhattan_distance(list((1, 2)), [1, 2])","handlingStrategy":"validation","validationCode":"point_a = list(point_a)\npoint_b = list(point_b)  # accepts tuples, arrays, Series","typeGuard":"def is_valid_point(p) -> bool:\n    return isinstance(p, list)","tryCatchPattern":null,"preventionTips":["Call .tolist() on numpy arrays and list() on tuples before passing.","Standardize your codebase on lists for point representations."],"tags":["math","typeerror","type-validation","distance-metrics"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}