human
Minimum shifts of substrings of 1 s required to group all 1 s together in a given Binary string | Function to count indices substrings of 1 s need to be shifted such that all 1 s in the string are grouped together.
Stores first occurrence of '1.
Stores last occurrence of '1.
Count of 0 s between firstOne and lastOne.
Traverse the string to find the first and last occurrences of '1.
Count number of 0 s present between firstOne and lastOne.
Print minimum operations.
Given string"
How can the above be solved in Python?

Give me a code to minimum shifts of substrings of 1 s required to group all 1 s together in a given Binary string and the other steps required?
assistant
#Here is code to minimum shifts of substrings of 1 s required to group all 1 s together in a given Binary string and the other steps required.
 def countShifts ( str ) :
'
	firstOne = - 1
'
	lastOne = - 1
	count = 0
'
	for i in range ( len ( str ) ) :
		if ( str [ i ] == '1' ) :
			if ( firstOne == - 1 ) :
				firstOne = i
			lastOne = i
	if ( ( firstOne == - 1 ) or ( firstOne == lastOne ) ) :
		print ( 0 )
		return
	for i in range ( firstOne , lastOne + 1 , 1 ) :
		if ( str [ i ] == '0' ) :
			count += 1
	print ( count )
str = "00110111011"
countShifts ( str )