I have the following input:
newValue = [['men', 'John Doe,Chris perry'], ['women', 'Mary,Anne,Lita']] - list within list
keywords_list = [('MEN', 'john,zack')] - tuple in a list (Dictionary on which .items() is used.)
Expected Output is:
newValue = [['men', 'John Doe'],['women','']]
What I want to do here is extract those names for Men which is common in both newValue and keywords_list.
Below is my working implementation that gets the desired result:
allValues =  for item in newValue: for key in keywords_list: if str(item)[1:].upper() == key: ValueSplit = item.split(',') keyWordSplit = key.split(',') for EverySplit in ValueSplit: for everyKey in keyWordSplit: if everyKey.lower() in EverySplit.lower(): pass else: ValueSplit.remove(EverySplit) item= ValueSplit allValues.append(item)
This isn't an efficient way of solving the problem. If anyone could recommend an efficient way with lesser complexity to achieve the desired result, it would be really helpful.