如何在列表中找出以元音开头的单词? [英] How to find out the words begin with vowels in a list?

查看:81
本文介绍了如何在列表中找出以元音开头的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

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']

这篇关于如何在列表中找出以元音开头的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆