为什么我的输出只显示单个元素

时间:2016-10-03 10:14:56

标签: python python-3.x

我试图将列表作为参数,并查找列表中的每个名称是否以元音结尾。但是,我继续得到一个元素而不是所有元素

a_list = ["Renjie",  "Shannon",  "Benjamin",  "Peron",  "Abhay",  "Peron",  "Ryan",  "Jingyi",  "David",  "Shan",  "Atunaisa",  "James",  "Joshua",  "Rory",  "Wayne",  "Raymond",  "Amy",  "Franco",  "Siran",  "Siyan",  "Dokyung",  "Hansoo",  "Adefolakanmi",  "Belita",  "Da",  "Qihao",  "Campbell",  "Chester",  "Daniel",  "alex",  "Rachel",  "Mitchell",  "Angelo",  "Bishoy",  "Freshteh",  "Kunyu",  "Lefei",  "Michael",  "alex",  "Minsuck",  "Angel",  "Sayaka",  "Changhao",  "Pramith",  "Minsang",  "Shuliang",  "Jiaqi",  "Mathew",  "Prashant",  "Alex"]
vowels = "aeiouAEIOU"
new_list = []
for word in a_list:
    if word[-1] in vowels:
       new_list.append(word)
       return new_list

1 个答案:

答案 0 :(得分:1)

正如Jim已经commented,你需要为return付出代价。除此之外,您可以使用列表理解:

new_list = [word for word in a_list if word[-1] in vowels]