如果我有一个清单,比如list = [abc都是字母,大象,香蕉是黄色,苹果是水果]或类似的东西,我怎么算这个单词'的次数&# 39;出现在这个列表中?
答案 0 :(得分:1)
您不应该使用list
作为变量名称,但这可以使用:
my_list = ["abc are all letters", "elephants", "bananas are yellow", "apples are fruits"]
count = 0
for string in my_list:
if "are" in string:
count += 1
答案 1 :(得分:0)
los = ["abc are all letters, elephants", "bananas are yellow, apples are fruits"]
sum((itm.count("are") for itm in los))