我将详细解释我需要什么:
我正在使用feedparser解析Python中的RSS提要。当然,这个提要有一个条目列表,有标题、链接和描述,就像普通的RSS提要一样。在
另一方面,我有一个字符串列表,其中包含一些我需要在项目描述中找到的关键字。在
我需要做的是找到关键字匹配最多的项
示例:
RSS源
Lion...
The lion (Panthera leo) is one of the four big cats in the genus
Panthera, and a member of the family Felidae.
Panthera...
Panthera is a genus of the Felidae (cats), which contains
four well-known living species: the tiger, the lion, the jaguar, and the leopard.
Cat...
The domestic cat is a small, usually furry, domesticated,
carnivorous mammal. It is often called the housecat, or simply the
cat when there is no need to distinguish it from other felids and felines.
关键字列表
^{pr2}$
所以在本例中,匹配最多(唯一)的项是第一个,因为它包含所有4个关键字(不管它说的是“cats”而不是“cat”,我只需要在字符串中找到literal关键字)
让我澄清一下,即使某些描述包含了“cat”关键字100次(而不是其他关键字),这也不会是赢家,因为我要查找包含的关键字最多的,而不是关键字出现次数最多的。在
现在,我在rss项目上循环,并“手动”地进行,计算关键字出现的次数(但我遇到了上面段落中提到的问题)。在
我对Python很陌生,而且我来自一种不同的语言(C#),所以如果这很微不足道,我很抱歉。在
你将如何处理这个问题?