human
Count substrings with same first and last characters | Space efficient Python3 program to count all substrings with same first and last characters ..
Iterating through all substrings in way so that we can find first and last character easily.
Driver Code"
How can the above be solved in Python?
 What is a code to count substrings with same first and last characters and the other steps required?
assistant
#Here is code to count substrings with same first and last characters and the other steps required.
 def countSubstringWithEqualEnds ( s ) :
	result = 0 ;
	n = len ( s ) ;
	for i in range ( n ) :
		for j in range ( i , n ) :
			if ( s [ i ] == s [ j ] ) :
				result = result + 1
	return result
s = " abcab " ;
print ( countSubstringWithEqualEnds ( s ) )