human
What is a code to lexicographically next string and the other steps required given the following:
Lexicographically next string | Python 3 program to find lexicographically next string.
If string is empty ..
Find first character from right which is not z ..
If all characters are ' z ' , append an ' a ' at the end ..
If there are some non - z characters.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to lexicographically next string and the other steps required.
 def nextWord ( s ) :
	if ( s == " ▁ " ) :
		return " a "
	i = len ( s ) - 1
	while ( s [ i ] == ' z ' and i >= 0 ) :
		i -= 1
	if ( i == - 1 ) :
		s = s + ' a '
	else :
		s = s . replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )
	return s
if __name__ == ' _ _ main _ _ ' :
	str = " samez "
	print ( nextWord ( str ) )