{"record":{"id":"aab02e4bde7833b4","repo":"TheAlgorithms/Python","slug":"expected-a-list-of-numbers-as-input-found-type-i","errorCode":null,"errorMessage":"Expected a list of numbers as input, found {type(item).__name__}","messagePattern":"Expected a list of numbers as input, found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"maths/manhattan_distance.py","lineNumber":73,"sourceCode":"    TypeError: Expected a list of numbers as input, found str\n    >>> _validate_point(1)\n    Traceback (most recent call last):\n         ...\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])","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/manhattan_distance.py#L55-L91","documentation":"Raised by _validate_point() in maths/manhattan_distance.py when an element inside the point list is not an int or float. The validator iterates each item and raises TypeError with the offending item's type name embedded in the message (e.g. 'found str'). It is called by manhattan_distance() and manhattan_distance_one_liner() on both points.","triggerScenarios":"manhattan_distance([1,'two'], [1,2]) raises 'found str'; manhattan_distance([1,None], [1,2]) raises 'found NoneType'; manhattan_distance([1, 1], [2, True]) passes since bool subclasses int.","commonSituations":"Vectors parsed from CSV/JSON where numbers stay strings, lists containing None for missing data, or mixed-type columns not coerced with pd.to_numeric.","solutions":["Coerce the whole list before calling: [float(x) for x in point].","Strip or impute None/missing values during preprocessing instead of leaving them in the vector.","When reading CSVs, use converters or dtype so numeric columns parse as numbers."],"exampleFix":"# before\nmanhattan_distance([1, '2'], [3, 4])\n\n# after\nmanhattan_distance([1, 2], [3, 4])  # or [float(x) for x in point_a]","handlingStrategy":"validation","validationCode":"point_a = [float(x) for x in point_a]\npoint_b = [float(x) for x in point_b]","typeGuard":"def is_numeric_list(p) -> bool:\n    return isinstance(p, list) and all(isinstance(x, (int, float)) and not isinstance(x, bool) for x in p)","tryCatchPattern":null,"preventionTips":["Coerce numeric columns with pd.to_numeric or float() at load time.","Impute or drop missing values before building distance vectors."],"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"}