I am having some trouble with lists. So, basically, I have a list:
a=["Britney spears", "red dog", "\xa2xe3"]
and I have another list, looking like:
b = ["cat","dog","red dog is stupid", "good stuff \xa2xe3", "awesome Britney spears"]
what I would like to do is check if elements in a are part of some element in b – and if so, remove them from b‘s element. So, I would like b to look like:
b = ["cat","dog","is stupid","good stuff","awesome"]
what is the most pythonic (in 2.7.x) way to achieve this?
I am assuming I can loop around to check each element, but I am not sure this is very efficient – I have a list (b) of around size 50k.
I think I’d use a regex here:
This way, the regular expression engine can optimize the test for the list of alternatives.
Here are a bunch of alternatives to show how different regexs behave.