Use collections.Counterand its methodmost_common
from collections import Counter
def vowels(s) :
vow_found = [i for i in s.lower() if i in 'aeiou']
c = Counter(vow_found)
return len(vow_found), c.most_common()
line = input("Type a line of text: ")
numvow, most_com = vowels(line)
print("The line contains", numvow, "vowels")
print("and the most common are", most_com)
which with the entrance
hello I am your friend today
produces
The line contains 10 vowels
and the most common are [('o', 3), ('i', 2), ('a', 2), ('e', 2), ('u', 1)]
source
share