human
Can you provide a code to reverse a string preserving space positions and the other steps required given the following:
Reverse a string preserving space positions | Python3 program to implement the above approach.
Initialize two pointers as two corners.
Move both pointers toward each other.
If character at start or end is space , ignore it.
If both are not spaces , do swap.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to reverse a string preserving space positions and the other steps required.
 def preserveSpace ( Str ) :
	n = len ( Str )
	Str = list ( Str )
	start = 0
	end = n - 1
	while ( start < end ) :
		if ( Str [ start ] == ' ▁ ' ) :
			start += 1
			continue
		elif ( Str [ end ] == ' ▁ ' ) :
			end -= 1
			continue
		else :
			Str [ start ] , Str [ end ] = ( Str [ end ] , Str [ start ] )
			start += 1
			end -= 1
	print ( ' ' . join ( Str ) )
Str = " internship ▁ at ▁ geeks ▁ for ▁ geeks "
preserveSpace ( Str ) ;