Python: matrix is added

This commit is contained in:
Dmitry Kokorin 2021-06-07 17:17:29 +03:00
parent ea87636a4f
commit 5e8a3b70f0
4 changed files with 154 additions and 0 deletions

16
python/matrix/matrix.py Normal file
View file

@ -0,0 +1,16 @@
class Matrix:
def __init__(self, matrix_string):
self.rows = [[int(s) for s in row_string.split()]
for row_string in matrix_string.split('\n')]
def row(self, index):
if index < 1:
raise ValueError("Row index must be no less than 1")
return self.rows[index - 1]
def column(self, index):
if index < 1:
raise ValueError("Row index must be no less than 1")
return [row[index - 1] for row in self.rows]