I have two lists: list message
and list keyword
. List message
looks like this:
message = ["my name is blabla",'x-men is a good movie','i deny that fact']
keyword = ['x-men','name is','psycho movie']
I want to make a new list which contains keywords that are present in the message.
newList = []
for message_index in message:
print(newList)
for keyword in keywords:
if search(r'\b{}\b'.format(keyword), message_index):
newList.append(keyword)
My python code is above, the problem is each sentence in my message list is around 100 to 150 words and the length of the list is 3000. Each keyword maybe one or two words and the length of the list is 12,000.
So the search is taking a long time, is there a shorter way to do it?
This question is different because of the large amount of data in both list.