human
Can you provide a code to check if a given string can be formed using characters of adjacent cells of a Matrix and the other steps required given the following:
Check if a given string can be formed using characters of adjacent cells of a Matrix | Function to check if the word exists.
If index exceeds board range.
If the current cell does not contain the required character.
If the cell contains the required character and is the last character of the word required to be matched.
Return true as word is found.
Mark cell visited.
Check Adjacent cells for the next character.
Restore cell value.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if a given string can be formed using characters of adjacent cells of a Matrix and the other steps required.
 def checkWord ( board , word , index , row , col ) :
	if ( row < 0 or col < 0 or row >= len ( board ) or col >= len ( board [ 0 ] ) ) :
		return False
	if ( board [ row ] [ col ] != word [ index ] ) :
		return False
	elif ( index == len ( word ) - 1 ) :
		return True
	temp = board [ row ] [ col ]
	board [ row ] [ col ] = ' * '
	if ( checkWord ( board , word , index + 1 , row + 1 , col ) or checkWord ( board , word , index + 1 , row - 1 , col ) or checkWord ( board , word , index + 1 , row , col + 1 ) or checkWord ( board , word , index + 1 , row , col - 1 ) ) :
		board [ row ] [ col ] = temp
		return True
	board [ row ] [ col ] = temp
	return False
if __name__ == " _ _ main _ _ " :
	board = [ [ ' A ' , ' B ' , ' C ' , ' E ' ] , [ ' S ' , ' F ' , ' C ' , ' S ' ] , [ ' A ' , ' D ' , ' E ' , ' E ' ] ]
	word = " CFDASABCESEE "
	f = 0
	for i in range ( len ( board ) ) :
		for j in range ( len ( board [ 0 ] ) ) :
			if ( board [ i ] [ j ] == word [ 0 ] and checkWord ( board , word , 0 , i , j ) ) :
				print ( " True " )
				f = 1
				break
		if f == 1 :
		break
	if f == 0 :
	print ( " False " )