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

Method validate_indices

matrix/sherman_morrison.py:57–73  ·  view source on GitHub ↗

Check if given indices are valid to pick element from matrix. Example: >>> a = Matrix(2, 6, 0) >>> a.validate_indices((2, 7)) False >>> a.validate_indices((0, 0)) True

(self, loc: tuple[int, int])

Source from the content-addressed store, hash-verified

55 return str(self)
56
57 def validate_indices(self, loc: tuple[int, int]) -> bool:
58 """
59 <method Matrix.validate_indicies>
60 Check if given indices are valid to pick element from matrix.
61 Example:
62 >>> a = Matrix(2, 6, 0)
63 >>> a.validate_indices((2, 7))
64 False
65 >>> a.validate_indices((0, 0))
66 True
67 """
68 if not (isinstance(loc, (list, tuple)) and len(loc) == 2): # noqa: SIM114
69 return False
70 elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
71 return False
72 else:
73 return True
74
75 def __getitem__(self, loc: tuple[int, int]) -> Any:
76 """

Callers 2

__getitem__Method · 0.95
__setitem__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected