Skip to content Skip to sidebar Skip to footer

Comparing Data Using Lookup And Output Only Longest Phrase In The Data Using Python?

I have a csv which contains 'KKR' map to 'MBI' data. I want to perform a lookup from a user given data to extract the longest matched phrase from KKR (ignore small phrase if it con

Solution 1:

import re

list_of_strings=["skin allergy","hair loss","allergy","hair", "skin"]
sentence="She experienced skin allergy and hair loss after using it for 2-3 weeks"
pattern = re.compile(r"(\b" + "|".join(list_of_strings) + r")\b")

m = pattern.findall(sentence)
print(m)

Post a Comment for "Comparing Data Using Lookup And Output Only Longest Phrase In The Data Using Python?"