Write a Python program to count number of substrings with same first and last characters of a given string.


Topic: Write a Python program to count number of substrings with same first and last characters of a given string.

Solution

def no_of_substring_with_equalEnds(str1): 
	result = 0; 
	n = len(str1); 
	for i in range(n): 
		for j in range(i, n): 
			if (str1[i] == str1[j]): 
				result = result + 1
	return result
 



List all Python Programs