MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _validate_list

Function _validate_list

dynamic_programming/viterbi.py:264–283  ·  view source on GitHub ↗

>>> _validate_list(["a"], "mock_name") >>> _validate_list("a", "mock_name") Traceback (most recent call last): ... ValueError: mock_name must be a list >>> _validate_list([0.5], "mock_name") Traceback (most recent call last): ... ValueError: mock_

(_object: Any, var_name: str)

Source from the content-addressed store, hash-verified

262
263
264def _validate_list(_object: Any, var_name: str) -> None:
265 """
266 >>> _validate_list(["a"], "mock_name")
267 >>> _validate_list("a", "mock_name")
268 Traceback (most recent call last):
269 ...
270 ValueError: mock_name must be a list
271 >>> _validate_list([0.5], "mock_name")
272 Traceback (most recent call last):
273 ...
274 ValueError: mock_name must be a list of strings
275 """
276 if not isinstance(_object, list):
277 msg = f"{var_name} must be a list"
278 raise ValueError(msg)
279 else:
280 for x in _object:
281 if not isinstance(x, str):
282 msg = f"{var_name} must be a list of strings"
283 raise ValueError(msg)
284
285
286def _validate_dicts(

Callers 1

_validate_listsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected