human
Check if all substrings of length K of a Binary String has equal count of 0 s and 1 s | Function to check if the substring of length K has equal 0 and 1.
Traverse the string.
Check if every K - th character is the same or not.
Traverse substring of length K.
If current character is 0.
Increment count.
Otherwise.
Decrement count.
Check for equal 0 s and 1 s.
Driver code"
How can the above be solved in Python?

Give me a code to check if all substrings of length K of a Binary String has equal count of 0 s and 1 s and the other steps required?
assistant
#Here is code to check if all substrings of length K of a Binary String has equal count of 0 s and 1 s and the other steps required.
 def check ( s , k ) :
	n = len ( s )
	for i in range ( k ) :
		for j in range ( i , n , k ) :
			if ( s [ i ] != s [ j ] ) :
				return False
	c = 0
	for i in range ( k ) :
		if ( s [ i ] == '0' ) :
			c += 1
		else :
			c -= 1
	if ( c == 0 ) :
		return True
	else :
		return False
s = "101010"
k = 2
if ( check ( s , k ) != 0 ) :
	print ( " Yes " )
else :
	print ( " No " )