class Matrix:
def __init__(self, matrix_string):
matrix = []
matrix_string = matrix_string.split('\n')
[matrix.append(i.split(' ')) for i in matrix_string]
self.matrix = [list(map(int, i)) for i in matrix]
def row(self, index):
return self.matrix[index - 1]
def column(self, index):
return [i[index - 1] for i in self.matrix]
I have an issue with line 5, though: you shouldn't use list comprehensions with side effects! Nested LCs have their own problems, but in this case it should be OK.
[matrix.append(i.split(' ')) for i in matrix_string]
происходит изменение списка matrix.