I have one list of string and one dictionary. For eg:
list = ["apple fell on Newton", "lemon is yellow","grass is greener"]
dict = {"apple" : "fruits", "lemon" : "vegetable"}
Task is to match each string from list with the key of dictionary. If it matches then return the value of the key.
Currently, I am using this approach which is very time consuming. Can someone please help me out with any efficient technique ?
lmb_extract_type = (lambda post: list(filter(None, set(dict.get(w)[0] if w in post.lower().split() else None for w in dict))))
df['type'] = df[list].apply(lmb_extract_type)
dfhere is, but for the 2 inputs that you have provided, do check my answer. On a side note, try not usinglistanddictas variable names specially when you are also usinglist()ordict()for data type conversion :)