Skip to content
Advertisement

How to find out the words begin with vowels in a list?

words = ['apple', 'orange', 'pear', 'milk', 'otter', 'snake', 'iguana',
         'tiger', 'eagle']
vowel=[]
for vowel in words:
    if vowel [0]=='a,e':
        words.append(vowel)
    print (words)

My code doesn’t right, and it will print out all the words in the original list.

Advertisement

Answer

words = ['apple', 'orange', 'pear', 'milk', 'otter', 'snake','iguana','tiger','eagle']
for word in words:
    if word[0] in 'aeiou':
        print(word)

You can also use a list comprehension like this

words_starting_with_vowel = [word for word in words if word[0] in 'aeiou']
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement