- 此问题在此处已有答案**:
(29个答案)
20小时前关门了。
我正在努力实现这一目标
string_list = ["red","blue","green"]
text = "This is a string about my favourite colours like red blue and green but blue is the best"
some_function(string_list,text)
Output: [1,2,1]
我该如何实现呢?得到一个将所有出现次数相加的数字(本例中为4)是没有问题的,但我希望它被string_list项分隔开。
3条答案
按热度按时间5us2dqdw1#
hs1rzwqc2#
下面是一个很长的方法:
relj7zay3#
你可以使用
count()
函数来计算字符串中的子字符串。下面的代码可能会有所帮助输出