human
Give me a code to reverse words in a given string and the other steps required given the following:
Reverse words in a given string | Reverse the string.
Check if number of words is even.
Find the middle word.
Starting from the middle start swapping words at jth position and l - 1 - j position.
Check if number of words is odd.
Find the middle word.
Starting from the middle start swapping the words at jth position and l - 1 - j position.
return the reversed sentence.
Driver Code"
Solution in Python:
assistant
#Here is code to reverse words in a given string and the other steps required.
 def RevString ( s , l ) :
	if l % 2 == 0 :
		j = int ( l / 2 )
		while ( j <= l - 1 ) :
		s [ j ] , s [ l - j - 1 ] = s [ l - j - 1 ] , s [ j ]
		j += 1
	else :
		j = int ( l / 2 + 1 )
		while ( j <= l - 1 ) :
		s [ j ] , s [ l - 1 - j ] = s [ l - j - 1 ] , s [ j ]
		j += 1
		return s ;
s = ' getting ▁ good ▁ at ▁ coding ▁ needs ▁ a ▁ lot ▁ of ▁ practice '
string = s . split ( ' ▁ ' )
string = RevString ( string , len ( string ) )
print ( " ▁ " . join ( string ) )