In this program, we will take a string as input and count vowels in each word in the given string show as dictionary output
Steps to solve the program
- Take a string as input.
- Convert the string of words into a list using split() method and create another string that contains all the vowels, also create an empty dictionary.
- Use For loop to iterate over every word in the list and count the number of vowels it contains.
- Add the word as key and its vowel count as the value in the dictionary.
- Repeat the process for each word.
- Print the output.
#Input string
string= "We are Learning Python Codding"
#Splitting the string
list1 = string.split(" ")
#Creating vowels list
vowels = "aeiou"
#creating an empty dictionary
dictionary = dict()
for word in list1:
count = 0
for char in word:
if char in vowels:
count +=1
dictionary[word] = count
#Printing output
print(dictionary)
Output :
{'We': 1, 'are': 2, 'Learning': 3,'Python': 1,'Codding': 2}