human
Longest alternating sub | Function to calculate alternating sub - array for each index of array elements.
Initialize the base state of len [ ].
Calculating value for each element.
If both elements are different then add 1 to next len [ i + 1 ].
else initialize to 1.
Print lengths of binary subarrays ..
Driver code"
How can the above be solved in Python?
 Can you provide a code to longest alternating sub and the other steps required?
assistant
#Here is code to longest alternating sub and the other steps required.
 def alternateSubarray ( arr , n ) :
	len = [ ]
	for i in range ( n + 1 ) :
		len . append ( 0 )
	len [ n - 1 ] = 1
	for i in range ( n - 2 , - 1 , - 1 ) :
		if ( arr [ i ] ^ arr [ i + 1 ] == True ) :
			len [ i ] = len [ i + 1 ] + 1
		else :
			len [ i ] = 1
	for i in range ( n ) :
		print ( len [ i ] , " ▁ " , end = " " )
arr = [ True , False , True , False , False , True ]
n = len ( arr )
alternateSubarray ( arr , n )