In: Computer Science
python 3 please
Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string.
Note: don't worry about ties or capital letters
Hint: consider defining and using a separate function that counts the number of vowels in a given string
def vowelist(string):
a = 0
e = 0
i = 0
o = 0
u = 0
for k in string:
if k == 'a':
a = a + 1
if k == 'e':
e = e + 1
if k == 'i':
i = i + 1
if k == 'o':
o = o + 1
if k == 'u':
u = u + 1
lst = []
dic = {} # insert the values into the dictionary
dic['a'] = a
dic['e'] = e
dic['i'] = i
dic['o'] = o
dic['u'] = u
result = sorted(dic.items(), key=lambda x: x[1],
reverse=True)
for i in result:
return (i[0], i[1]) # return the tuple
string = input("Enter the string : ") # read the string
print(vowelist(string)) # print the result
OUTPUT :