Write a program to count characters surrounding vowels


Topic: Write a program to count characters surrounding vowels

Solution

str1 = 'week after week the numbers are increasing'
  
res = 0
vow_list = ['a', 'e', 'i', 'o', 'u']
for idx in range(1, len(str1) - 1): 
    if str1[idx] not in vow_list and (str1[idx - 1] in vow_list or str1[idx + 1] in vow_list): 
        res += 1
  
if str1[0] not in vow_list and str1[1] in vow_list: 
    res += 1
  
if str1[-1] not in vow_list and str1[-2] in vow_list: 
    res += 1
print("Characters around vowels count : " + str(res))



List all Python Programs