I want to count the number of sub-string within a string in python based on the 1st character (vowel/consonants) of the sub-string. For example, in the string 'Banana', 'an' is a sub-string that started with a vowel 'a', and it appears 2 times, so I want to count it twice. Same for the other combination ('ana'/ 'anan'...etc). And the sub-string can be repeated, meaning 'an' is also shown in 'ana', so it would be counted twice.
But I could only count the number of sub-string (vowel) appears in the string, is there a way to count the number of sub-string based on the 1st character of sub-string? Plus it should be repetitive like the 'an' and 'ana' case discussed above. Currently my code is as below. Thanks a lot!!
string = input() #User input a string with vowel and consonant
def minion_game(string):
count_v = 0 #count the number of sub-string started with vowel
count_c = 0 #count the number of sub-string started with consonant
for i in range(len(string)):
if string[i] == 'a' or string[i] == 'e' or string[i] == 'i' or string[i] == 'o' or string[i] == 'u':
count_c += 1
else:
count_v += 1
return count_v, count_c