def vowels(list):
res = []
for word in list:
vowel_n = 0
for x in word:
if x in 'aeiou':
vowel_n+=1
if vowel_n== 2:
res.append(word)
return res
print(vowels(['tragedy', 'proof', 'dog', 'bug', 'blastoderm']))
Result: [‘tragedy’]
I’m expecting to show all characters that only have 2 vowels
>Solution :
Try reducing the indentation level of the if vowel_n== 2: block. Currently, it’s not checking the vowel counter unless the letter is a vowel. Instead of return try using break to break the inner loop
And move return to outside of the loop. You’re returning the result after the first word that matches the condition.
Check out this repl.it project: https://replit.com/@HarunYilmaz1/PrudentPalegreenScans#main.py
def vowels(list):
res = []
for word in list:
vowel_n = 0
for x in word:
if x in 'aeiou':
vowel_n+=1
if vowel_n== 2:
res.append(word)
break
return res