def read_from_matrix(matrix, str1, str2):
 result = ''
 (i, j) = (len(str1), len(str2))
 while ((i != 0) and (j != 0)):
  if (matrix[i][j] == matrix[(i - 1)][j]):
   i -= 1
  elif (matrix[i][j] == matrix[i][(j - 1)]):
   j -= 1
  else:
   result += str1[(i - 1)]
   i -= 1
   j -= 1
 return result[::(-1)]

def read_from_matrix ( matrix , str1 , str2 ) : result = '' ( i , j ) = ( len ( str1 ) , len ( str2 ) ) while ( ( i != 0 ) and ( j != 0 ) ) : if ( matrix [ i ] [ j ] == matrix [ ( i - 1 ) ] [ j ] ) : i -= 1 elif ( matrix [ i ] [ j ] == matrix [ i ] [ ( j - 1 ) ] ) : j -= 1 else : result += str1 [ ( i - 1 ) ] i -= 1 j -= 1 return result [ : : ( - 1 ) ]
xxx: needs documentation written .