My main string is in dataframe and substrings are stored in lists. My desired output is to find the matched substring. Here is the code I am using.
sentence2 = "Previous study: 03/03/2018 (other hospital) Findings: Lung parenchyma: The study reveals evidence of apicoposterior segmentectomy of LUL showing soft tissue thickening adjacent surgical bed at LUL, possibly post operation."
blob_sentence = TextBlob(sentence2)
noun = blob_sentence.noun_phrases
df1 = pd.DataFrame(noun)
comorbidity_keywords = ["segmentectomy","lobectomy"]
matches =[]
for comorbidity_keywords[0] in df1:
if comorbidity_keywords[0] in df1 and comorbidity_keywords[0] not in matches:
matches.append(comorbidity_keywords)
This gives me the result as the string that is not an actual match. The output should be "segmentectomy". But I get [0,'lobectomy']. Please Help!!. I have tried to take help from the answer posted here. Check if multiple strings exist in another string Please help to find out what am I doing incorrectly?