human
Give me a code to lexicographically smallest and largest substring of size k and the other steps required given the following:
Lexicographically smallest and largest substring of size k | Python 3 program to find lexicographically largest and smallest substrings of size k ..
Initialize min and max as first substring of size k.
Consider all remaining substrings . We consider every substring ending with index i ..
Print result ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to lexicographically smallest and largest substring of size k and the other steps required.
 def getSmallestAndLargest ( s , k ) :
	currStr = s [ : k ]
	lexMin = currStr
	lexMax = currStr
	for i in range ( k , len ( s ) ) :
		currStr = currStr [ 1 : k ] + s [ i ]
		if ( lexMax < currStr ) :
			lexMax = currStr
		if ( lexMin > currStr ) :
			lexMin = currStr
	print ( lexMin )
	print ( lexMax )
if __name__ == ' _ _ main _ _ ' :
	str1 = " GeeksForGeeks "
	k = 3
	getSmallestAndLargest ( str1 , k )