def replace(diagonal, matrix):
matrix[0][0] = diagonal[0]
try:
matrix[1][1] = diagonal[1]
except IndexError:
pass
try:
matrix[2][2] = diagonal[2]
except IndexError:
pass
return matrix