human
Give me a code to count substrings with same first and last characters and the other steps required given the following:
Count substrings with same first and last characters | Returns true if first and last characters of s are same ..
Starting point of substring.
Length of substring.
Check if current substring has same starting and ending characters ..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count substrings with same first and last characters and the other steps required.
 def checkEquality ( s ) :
	return ( ord ( s [ 0 ] ) == ord ( s [ len ( s ) - 1 ] ) ) ;
def countSubstringWithEqualEnds ( s ) :
	result = 0 ;
	n = len ( s ) ;
	for i in range ( n ) :
		for j in range ( 1 , n - i + 1 ) :
			if ( checkEquality ( s [ i : i + j ] ) ) :
				result += 1 ;
	return result ;
s = " abcab " ;
print ( countSubstringWithEqualEnds ( s ) ) ;