Reputation: 1846
Example:
a = ['abc123','abc','543234','blah','tete','head','loo2']
So I want to filter out from the above array of strings the following array b = ['ab','2']
I want to remove strings containing 'ab' from that list along with other strings in the array so that I get the following:
a = ['blah', 'tete', 'head']
Upvotes: 0
Views: 96
Reputation: 1839
newA = []
for c in a:
for d in b:
if d not in c:
newA.append(c)
break
a = newA
Upvotes: 1
Reputation: 104111
>>> a = ['abc123','abc','543234','blah','tete','head','loo2']
>>> b = ['ab','2']
>>> [e for e in a if not [s for s in b if s in e]]
['blah', 'tete', 'head']
Upvotes: 2
Reputation: 60024
You can use a list comprehension:
[i for i in a if not any(x in i for x in b)]
This returns:
['blah', 'tete', 'head']
Upvotes: 5