示例:
a = ['abc123','abc','543234','blah','tete','head','loo2']
所以我想从上面的数组字符串中筛选出以下数组b = ['ab','2']
我想从该列表中删除包含'ab'的字符串以及数组中的其他字符串,以便我得到以下内容:
a = ['blah', 'tete', 'head']
答案 0 :(得分:5)
您可以使用列表理解:
[i for i in a if not any(x in i for x in b)]
返回:
['blah', 'tete', 'head']
答案 1 :(得分:2)
>>> 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']
答案 2 :(得分:1)
newA = []
for c in a:
for d in b:
if d not in c:
newA.append(c)
break
a = newA