擅长:python、mysql、java
<p>给定的数据是tuple,因为它们来自DB。因此,您可能需要先更改数据(当然有不同的方法。)</p>
<pre><code>Keywords =(('Nike shoes',),('Adidas shoes',),('Levice Jeans',),('adidas jersey',))
Chats = (('Nike shoes have an offer',),('They are at a discount',),
('Nike shoes are the best',),('They have other offers as well',),
('They have introduced new shoes which are awesome',))
# Make them lists because it's easy to use in your case
keywords = [keyword[0].lower() for keyword in Keywords]
chats = [chat[0].lower() for chat in Chats]
# Store all the common words into list3
list3 = []
for keyword in keywords:
if any(keyword in chat for chat in chats):
list3.append(keyword)
print(list3)
# ['nike shoes']
</code></pre>
<p>当前数据不需要<code>keyword[0].lower()</code>部分,但将所有文本转换为小写进行比较可能会有所帮助</p>