Reputation: 9
I want the user to be able to enter a piece of string (I know how to do this)
Then I want Python to count how many times each vowel (aeiou) is used.
After counting how many times each vowel is used, I need the program to return the least used vowel/s which is/are used at least once. If a vowel is not used it should not be returned. In the event of a tie for least used both should be returned.
If no vowels are used, it should print an error code "No vowels were used" (I know how to do this)
For example: If this is how many times the vowels were used in a sentence:
a=4
b=2
c=0
d=0
e=2
It should print "The least USED vowels were b and c, with 2 uses".
Upvotes: 0
Views: 198
Reputation: 11
I would suggest to sort the letters based on their values and remove the consonants and print the first vowel.
Upvotes: 0
Reputation: 62636
You can:
Counter
on the list you got from #2.import re
from collections import Counter
s = 'asdfwerasdfwaxciduso'
only_vowels = re.sub(r"[^aeiou]", "", s)
c = Counter(list(only_vowels))
c.most_common()[-1]
Upvotes: 1
Reputation: 451
Do it the hard way - letter by letter. Iterate over the string with a for loop and for each letter increment a dictionary value. At the end, check the keys with vowels and find the smallest.
Upvotes: 0