I have a list of phrases and I am trying to identify keywords in each phrase. Using re.search I am able to find the keywords I am looking for in each phrase. When I use a keyword for goals, it detects the presence of the keyword but does not return it.
Here is an example of what I have tried:
#Keywords I am looking for.
keywords = [‘goalw*’,’although’]
def keyword(text):
matchfound = [key for key in keywords if re.search(r’b’+key+r’b’, text)]
result = []
[result.append(x) for x in matchfound if x not in result]
return result
output = keyword(“His goals were accomplished as expected”)
output
[‘goalw*’]
#I was expecting to see “goals”
#My intention is to apply this code to a dataset with 1000+ rows of phrases.
When I tried compile as outlined in a previous answer (How to return full substring from partial substring match in python as a list?), i get “TypeError: unsupported operand type(s) for &: ‘str’ and ‘int’.”
Thank you.
Conrad K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.