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

Method add_column

matrix/matrix_class.py:265–284  ·  view source on GitHub ↗
(self, column: list[int], position: int | None = None)

Source from the content-addressed store, hash-verified

263 self.rows = [*self.rows[0:position], row, *self.rows[position:]]
264
265 def add_column(self, column: list[int], position: int | None = None) -> None:
266 type_error = TypeError(
267 "Column must be a list containing all ints and/or floats"
268 )
269 if not isinstance(column, list):
270 raise type_error
271 for value in column:
272 if not isinstance(value, (int, float)):
273 raise type_error
274 if len(column) != self.num_rows:
275 raise ValueError(
276 "Column must be equal in length to the other columns in the matrix"
277 )
278 if position is None:
279 self.rows = [self.rows[i] + [column[i]] for i in range(self.num_rows)]
280 else:
281 self.rows = [
282 [*self.rows[i][0:position], column[i], *self.rows[i][position:]]
283 for i in range(self.num_rows)
284 ]
285
286 # MATRIX OPERATIONS
287 def __eq__(self, other: object) -> bool:

Callers 1

display_billionairesFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected