def mulmatmat(matlist1, matlist2, K):
 matcol = [list(i) for i in zip(*matlist2)]
 result = []
 for row in matlist1:
  result.append([mulrowcol(row, col, K) for col in matcol])
 return result

def mulmatmat ( matlist1 , matlist2 , K ) : matcol = [ list ( i ) for i in zip ( * matlist2 ) ] result = [ ] for row in matlist1 : result . append ( [ mulrowcol ( row , col , K ) for col in matcol ] ) return result
multiplies two matrices by multiplying each row with each column at a time .