python - Nested for loop to match vowels by iterating over strings and lists -
this question has answer here:
- python: counting vowels list 4 answers
i trying loop on list, , match each character in list characters in string:
wordlist = ['big', 'cats', 'like', 'really'] vowels = "aeiou" count = 0 in range(len(wordlist)): j in vowels: if j in wordlist[i]: count +=1 print(j,'occurs', count,'times')
to return "a" occurs 2 times.
each vowel not work. doing wrong?
try this:
wordlist = ['big', 'cats', 'like', 'really'] vowels = "aeiou" v in vowels: count = 0 word in wordlist: if v in word: count += 1 print(v,'occurs', count, 'times')
results:
a occurs 2 times e occurs 2 times occurs 2 times o occurs 0 times u occurs 0 times
Comments
Post a Comment