Python: matrix is added
This commit is contained in:
parent
ea87636a4f
commit
5e8a3b70f0
4 changed files with 154 additions and 0 deletions
16
python/matrix/matrix.py
Normal file
16
python/matrix/matrix.py
Normal 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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue