human
Count number of islands where every island is row | This function takes a matrix of ' X ' and ' O ' and returns the number of rectangular islands of ' X ' where no two islands are row - wise or column - wise adjacent , the islands may be diagonaly adjacent.
Initialize result.
Traverse the input matrix.
If current cell is ' X ' , then check whether this is top - leftmost of a rectangle . If yes , then increment count.
Driver Code"
How can the above be solved in Python?
 ... Can you provide a code to count number of islands where every island is row and the other steps required?
assistant
#Here is code to count number of islands where every island is row and the other steps required.
 def countIslands ( mat ) :
	count = 0 ;
	for i in range ( 0 , M ) :
		for j in range ( 0 , N ) :
			if ( mat [ i ] [ j ] == ' X ' ) :
				if ( ( i == 0 or mat [ i - 1 ] [ j ] == ' O ' ) and ( j == 0 or mat [ i ] [ j - 1 ] == ' O ' ) ) :
					count = count + 1
	return count
M = 6
N = 3
mat = [ [ ' O ' , ' O ' , ' O ' ] , [ ' X ' , ' X ' , ' O ' ] , [ ' X ' , ' X ' , ' O ' ] , [ ' O ' , ' O ' , ' X ' ] , [ ' O ' , ' O ' , ' X ' ] , [ ' X ' , ' X ' , ' O ' ] ]
print ( " Number ▁ of ▁ rectangular ▁ islands ▁ is " , countIslands ( mat ) )