比较 List of Sentences 和 List of words 和 return complete Sentences ,如果存在 word
Compare List of Sentences and List of words and return complete Sentences , if word is present
从句子列表和单词列表中,如何 return 完整句子列表(如果存在单词)。请建议。以下是示例列表。
listwords = ['people', 'Covid-19', 'Lockdowns', 'Maximum' ]
listsent = ['The number of people suffering acute hunger could almost double.',
'It is potentially catastrophic for millions',
'Lockdowns and global economic recession have',
'one more shock – like Covid-19 – to push them over the edge',
'people must collectively act now to mitigate the impact']
'people'出现在两个句子中,'Covid-19'出现在一个句子中,'Lockdown'出现在一个句子中。
输出列表应该包含来自 listsent 的这四个匹配的完整句子。
列表理解是一种快速的方法:
[sentence for sentence in listsent if any(word in sentence for word in listwords)]
从句子列表和单词列表中,如何 return 完整句子列表(如果存在单词)。请建议。以下是示例列表。
listwords = ['people', 'Covid-19', 'Lockdowns', 'Maximum' ]
listsent = ['The number of people suffering acute hunger could almost double.',
'It is potentially catastrophic for millions',
'Lockdowns and global economic recession have',
'one more shock – like Covid-19 – to push them over the edge',
'people must collectively act now to mitigate the impact']
'people'出现在两个句子中,'Covid-19'出现在一个句子中,'Lockdown'出现在一个句子中。 输出列表应该包含来自 listsent 的这四个匹配的完整句子。
列表理解是一种快速的方法:
[sentence for sentence in listsent if any(word in sentence for word in listwords)]