TheAlgorithms/Python · error · TypeError

Expected a list of numbers as input, found {type(point).__na

Error message

Expected a list of numbers as input, found {type(point).__name__}

What it means

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.

Source

Thrown at maths/manhattan_distance.py:76

         ...
    TypeError: Expected a list of numbers as input, found int
    >>> _validate_point("not_a_list")
    Traceback (most recent call last):
         ...
    TypeError: Expected a list of numbers as input, found str
    """
    if point:
        if isinstance(point, list):
            for item in point:
                if not isinstance(item, (int, float)):
                    msg = (
                        "Expected a list of numbers as input, found "
                        f"{type(item).__name__}"
                    )
                    raise TypeError(msg)
        else:
            msg = f"Expected a list of numbers as input, found {type(point).__name__}"
            raise TypeError(msg)
    else:
        raise ValueError("Missing an input")


def manhattan_distance_one_liner(point_a: list, point_b: list) -> float:
    """
    Version with one liner

    >>> manhattan_distance_one_liner([1,1], [2,2])
    2.0
    >>> manhattan_distance_one_liner([1.5,1.5], [2,2])
    1.0
    >>> manhattan_distance_one_liner([1.5,1.5], [2.5,2])
    1.5
    >>> manhattan_distance_one_liner([-3, -3, -3], [0, 0, 0])
    9.0
    >>> manhattan_distance_one_liner([1,1], None)
    Traceback (most recent call last):

View on GitHub (pinned to f5988cc097)

Solutions

  1. Wrap non-list sequences: manhattan_distance(list(point_a), list(point_b)).
  2. For numpy arrays use .tolist(): manhattan_distance(arr.tolist(), other).
  3. Standardize on lists when constructing the points you will pass to this API.

Example fix

# before
manhattan_distance((1, 2), [1, 2])

# after
manhattan_distance(list((1, 2)), [1, 2])
Defensive patterns

Strategy: validation

Validate before calling

point_a = list(point_a)
point_b = list(point_b)  # accepts tuples, arrays, Series

Type guard

def is_valid_point(p) -> bool:
    return isinstance(p, list)

Prevention

When it happens

Trigger: manhattan_distance((1,2), [1,2]) (tuple point), manhattan_distance('ab', [1,2]) (str), or manhattan_distance(np.array([1,2]), [1,2]) (ndarray).

Common situations: Passing tuples from function returns or namedtuple records, numpy arrays from vectorized code, or pandas Series — all common sequence types that are not list.

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/928ea8bb678ac4c3. Report an issue: GitHub.