human
Sort the given Matrix | Memory Efficient Approach | Function to sort the matrix.
Number of elements in matrix.
Loop to sort the matrix using Bubble Sort.
Condition to check if the Adjacent elements.
Swap if previous value is greater.
Loop to print the matrix.
Driver Code.
Function call to sort.
Function call to print matrix"
How can the above be solved in Python?
 Write me a code to sort the given Matrix and the other steps required?
assistant
#Here is code to sort the given Matrix and the other steps required.
 def sortMat ( data , row , col ) :
	size = row * col
	for i in range ( 0 , size ) :
		for j in range ( 0 , size - 1 ) :
			if ( data [ j // col ] [ j % col ] > data [ ( j + 1 ) // col ] [ ( j + 1 ) % col ] ) :
				temp = data [ j // col ] [ j % col ]
				data [ j // col ] [ j % col ] = data [ ( j + 1 ) // col ] [ ( j + 1 ) % col ]
				data [ ( j + 1 ) // col ] [ ( j + 1 ) % col ] = temp
def printMat ( mat , row , col ) :
	for i in range ( row ) :
		for j in range ( col ) :
			print ( mat [ i ] [ j ] , end = " ▁ " )
		print ( )
if __name__ == " _ _ main _ _ " :
	mat = [ [ 5 , 4 , 7 ] , [ 1 , 3 , 8 ] , [ 2 , 9 , 6 ] ]
	row = len ( mat )
	col = len ( mat [ 0 ] )
	sortMat ( mat , row , col )
	printMat ( mat , row , col )