Possible Duplicate:
Check if multiple strings exist in another string
假设我有一个允许使用的单词/短语的列表:
'Stack'
'Overflow'
'Stack Overflow'
'Stack Exchange'
'Exchange'
以及要解析的以下文本:
'Hello, and welcome to Stack Overflow.
Here are some words which should match: Stack, Exchange.'
我想获取在允许列表中找到的单词列表:
- “堆栈溢出”
- “堆栈”
- “交换”
实现这一结果的最佳方法是什么?
我将使用的允许列表可能至少有一千个单词/短语。
最佳答案
将单词放入列表中并在使用后
def intersect(x, y):
return list(set(x) & set(y))
word_list_text=string.split(text)
words_found={}
words_found=intersect(word_list_text, words)
关于python - 查找文本中单词列表中单词的出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14087336/