human
Give me a code to return previous element in an expanding matrix and the other steps required given the following:
Return previous element in an expanding matrix | Returns left of str in an expanding matrix of a , b , c , and d ..
Start from rightmost position.
If the current character is b or d , change to a or c respectively and break the loop.
If the current character is a or c , change it to b or d respectively.
Driver Code"
Solution in Python:
assistant
#Here is code to return previous element in an expanding matrix and the other steps required.
 def findLeft ( str ) :
	n = len ( str ) - 1 ;
	while ( n > 0 ) :
		if ( str [ n ] == ' d ' ) :
			str = str [ 0 : n ] + ' c ' + str [ n + 1 : ] ;
			break ;
		if ( str [ n ] == ' b ' ) :
			str = str [ 0 : n ] + ' a ' + str [ n + 1 : ] ;
			break ;
		if ( str [ n ] == ' a ' ) :
			str = str [ 0 : n ] + ' b ' + str [ n + 1 : ] ;
		elif ( str [ n ] == ' c ' ) :
			str = str [ 0 : n ] + ' d ' + str [ n + 1 : ] ;
		n -= 1 ;
	return str ;
if __name__ == ' _ _ main _ _ ' :
	str = " aacbddc " ;
	print ( " Left ▁ of " , str , " is " , findLeft ( str ) ) ;