I have two lists of strings as follow:
good_tags = ['c#', '.net', 'java']
all_tags = [['c# .net datetime'],
['c# datetime time datediff relative-time-span'],
['html browser timezone user-agent timezone-offset']]
My target is to keep only the 'good_tags' from the list of strings in the 'all_tags', for instance,
- the first row of 'all_tags':[c# .net datetime]
- shall become (based on list of strings I want to keep in 'good_tags') : [c# .net]
I have tried with 'in' instead of 'not in', based on Remove all the elements that occur in one list from another
y3 = [x for x in all_tags if x in good_tags]
print ('y3: ', y3)
y4 = [x for x in good_tags if x in all_tags]
print ('y4: ', y4)
OUT:
y3: []
y4: []