High Schooler here, i need help with a question. I have to count the number of vowels in a sentence and output the total no. of vowels along with the word with the most vowels. But I'm getting TypeError: list indices must be integers or slices, not tuple And cant really figure out how to solve it.
string = 'This is a string' vowels = 'AaEeIiOoUu' string = string.split(' ') for i in enumerate(string): word = string[i] count = [x for x in word if x in vowels] print(vowels) print(len(vowels))
While iterating enumerate it always uses a two-parameter(tuple). One is index and the other is an iterable object. Use a contemporary variable after i to iterate the string.
enumerate
i
string
for i,s in enumerate(string)
1.4m articles
1.4m replys
5 comments
56.9k users