Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python—如何计算字符串列表中部分字符串的出现次数_Python - Fatal编程技术网

Python—如何计算字符串列表中部分字符串的出现次数

Python—如何计算字符串列表中部分字符串的出现次数,python,Python,如果我有一个列表,比如list=[abc都是字母,大象,香蕉是黄色的,苹果是水果]或者类似的东西,我怎么计算“是”这个词出现在这个列表中的次数 您不应该使用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:

如果我有一个列表,比如list=[abc都是字母,大象,香蕉是黄色的,苹果是水果]或者类似的东西,我怎么计算“是”这个词出现在这个列表中的次数

您不应该使用
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

请发布真实的Python数据,并展示您自己尝试过的内容。使用循环。你尝试了什么?请看你能澄清一下我违反了指南的哪一部分吗?只回答代码对社区没有用处
los =  ["abc are all letters, elephants", "bananas are yellow, apples are fruits"]

sum((itm.count("are") for itm in los))