forked from course-work/week1
Done
This commit is contained in:
parent
4e1d357998
commit
fd9a28c43e
@ -5,6 +5,11 @@ def matrix_parse(matrix):
|
||||
|
||||
return out
|
||||
|
||||
def matrix_from_file(file):
|
||||
with open(file, 'r') as file:
|
||||
|
||||
return matrix_parse(file.read())
|
||||
|
||||
def matrix_sum(matrix):
|
||||
row_sum = []
|
||||
col_sum = [0 for col in range(len(matrix)+1)]
|
||||
@ -16,6 +21,26 @@ def matrix_sum(matrix):
|
||||
|
||||
return row_sum, col_sum
|
||||
|
||||
def sort_row(matrix):
|
||||
row_sum, col_sum = matrix_sum(matrix)
|
||||
out = []
|
||||
|
||||
for index, row in sorted( [i for i in enumerate(row_sum)], key=lambda x:x[1] ):
|
||||
out.append(matrix[index])
|
||||
|
||||
return out;
|
||||
|
||||
def sort_col(matrix):
|
||||
row_sum, col_sum = matrix_sum(matrix)
|
||||
out = []
|
||||
places = sorted( [i for i in enumerate(col_sum)], key=lambda x:x[1])
|
||||
|
||||
for index, row in enumerate(matrix):
|
||||
out.append([row[i[0]] for i in places])
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def matrix_get_element_width(matrix):
|
||||
max = 0
|
||||
for row in matrix:
|
||||
@ -32,11 +57,6 @@ def matrix_print(matrix, width=None):
|
||||
for row in matrix:
|
||||
print('', *['{:{}d}'.format(el, width) for el in row], '', sep=' | ')
|
||||
|
||||
def matrix_from_file(file):
|
||||
with open(file, 'r') as file:
|
||||
|
||||
return matrix_parse(file.read())
|
||||
|
||||
|
||||
m1 ='''10 5 4 20
|
||||
9 33 27 16
|
||||
|
Loading…
x
Reference in New Issue
Block a user