exercism-solutions/python/matrix/matrix.py
2021-06-07 17:17:29 +03:00

16 lines
499 B
Python

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]