Write a function vowel_indices() that takes a string as a parameter and returns
ID: 639614 • Letter: W
Question
Write a function vowel_indices() that takes a string as a parameter and returns a list of all the indices of all the vowels in the string. A vowel is one of a, e, i, o, or u. Capitalization should not matter in reporting the indices, meaning that upper- and lowercase vowels should have their indices printed. The following shows several sample runs of the function:
vowel_indices('Hello world!')
[1,4,7]
vowel_indices("Amber Settle")
[0,3,7,11]
vowel_indices(" ")
[]
vowel_indices("Testing testing")
[1,4,9,12]
vowel_indices('BCd')
[]
Explanation / Answer
def vowel_indices(str):
list_of_positions=[]
for character_position in range(len(str)):
if str[character_position] =='a' or str[character_position] =='e' or str[character_position] =='i' or str[character_position] =='o' or str[character_position] =='u':
list_of_positions.append(str[character_position])
print list_of_positions
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.