I want a Python function that can get a keyword from an input of a sentence and a list of keywords. The function will iterate over the keywords list and search in the sentence the given keywords. If there is a keyword in the sentence, the function will return the keyword. Else it will return None.
For example, I have a list ["ai", "Machine Learning", "Computer Science"] and a sentence "My major is Computer Science, and I am currently working as a retailer for a store". If the function is implemented correctly, it will output the keyword Computer Science. However, at the moment, my function is outputting both Computer Science and ai (retailer also has ai in it) since I am using Python IN. Is there any way that I can improve my function to get the more proper result?
Here is my attempted code:
sentence = "My major is Computer Science, and I am currently working as a retailer for a store" keywords_list = ["ai", "Machine Learning", "Computer Science"] output_list = list() for keyword in keywords_list: if keyword in sentence: output_list.append(keyword)