TheAlgorithms/Python · error · ValueError
Missing an input
Error message
Missing an input
What it means
Raised by _validate_point() in maths/manhattan_distance.py when the point is falsy — None, an empty list [], or an empty container. The `if point:` guard treats any empty input as a missing value and raises ValueError('Missing an input') before any dimension checks run.
Source
Thrown at maths/manhattan_distance.py:78
>>> _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):
...
ValueError: Missing an inputView on GitHub (pinned to f5988cc097)
Solutions
- Ensure both points contain data before calling; skip or impute empty records upstream.
- Default to a zero vector of the right dimension if an 'empty' point is semantically valid in your domain.
- Check `if not point_a or not point_b: ...` in your own code to handle the case explicitly.
Example fix
# before
manhattan_distance([], [1, 2])
# after
if point_a and point_b:
d = manhattan_distance(point_a, point_b)
else:
d = 0.0 # or skip the record Defensive patterns
Strategy: validation
Validate before calling
if not point_a or not point_b:
raise ValueError('both points are required') # or skip/impute the record Type guard
def is_non_empty_list(p) -> bool:
return isinstance(p, list) and len(p) > 0 Prevention
- Filter out empty records before batch distance computations.
- Never use [] as a default point value; require explicit data.
When it happens
Trigger: manhattan_distance([], [1,2]), manhattan_distance(None, [1,2]), or a point loaded from a row that was never populated (defaults to []).
Common situations: Empty vectors from filtered-out data, default-argument accumulation bugs where a list stays empty, or None leaking through optional fields.
Related errors
- The list is empty. Provide a non-empty list.
- Both points must be in the same n-dimensional space
- The order must be greater than or equal to 1.
- Both points must have the same dimension.
- surface_area_cube() only accepts non-negative values
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/7210dcc91bf33f67.
Report an issue: GitHub.