Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 
str1 = input("Input a string: ")
print(no_of_substring_with_equalEnds(str1))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now