How to print the least used vowel in a string?


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:


It should print “The least USED vowels were b and c, with 2 uses”.


You can:

  1. Remove all non-vowels chars from the string.
  2. Split the string by chars.
  3. use the 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))

Answered By – Dekel

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published