Vowels in each word of string show as dictionary

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
  1. Take a string as input.
  2. 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.
  3. Use For loop to iterate over every word in the list and count the number of vowels it contains.
  4. Add the word as key and its vowel count as the value in the dictionary.
  5. Repeat the process for each word.
  6. 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}
				
			

exchange the first and last character of each word from the given string.

repeat vowels 3 times and consonants 2 times.

Leave a Comment