human
Count subsequence of length three in a given string | Function to find number of occurrences of a subsequence of length three in a string.
calculate length of string.
auxiliary array to store occurrences of first character.
auxiliary array to store occurrences of third character.
calculate occurrences of first character upto ith index from left.
calculate occurrences of third character upto ith index from right.
variable to store total number of occurrences.
loop to find the occurrences of middle element.
if middle character of subsequence is found in the string.
multiply the total occurrences of first character before middle character with the total occurrences of third character after middle character.
Driver code"
How can the above be solved in Python?

=====
Give me a code to count subsequence of length three in a given string and the other steps required?
assistant
#Here is code to count subsequence of length three in a given string and the other steps required.
 def findOccurrences ( str1 , substr ) :
	n = len ( str1 )
	preLeft = [ 0 for i in range ( n ) ]
	preRight = [ 0 for i in range ( n ) ]
	if ( str1 [ 0 ] == substr [ 0 ] ) :
		preLeft [ 0 ] += 1
	for i in range ( 1 , n ) :
		if ( str1 [ i ] == substr [ 0 ] ) :
			preLeft [ i ] = preLeft [ i - 1 ] + 1
		else :
			preLeft [ i ] = preLeft [ i - 1 ]
	if ( str1 [ n - 1 ] == substr [ 2 ] ) :
		preRight [ n - 1 ] += 1
	i = n - 2
	while ( i >= 0 ) :
		if ( str1 [ i ] == substr [ 2 ] ) :
			preRight [ i ] = preRight [ i + 1 ] + 1
		else :
			preRight [ i ] = preRight [ i + 1 ]
		i -= 1
	counter = 0
	for i in range ( 1 , n - 1 ) :
		if ( str1 [ i ] == str1 [ 1 ] ) :
			total = preLeft [ i - 1 ] * preRight [ i + 1 ]
			counter += total
	return counter
if __name__ == ' _ _ main _ _ ' :
	str1 = " GFGFGYSYIOIWIN "
	substr = " GFG "
	print ( findOccurrences ( str1 , substr ) )