例子:
a = ['abc123','abc','543234','blah','tete','head','loo2']
所以我想从上面的字符串数组中过滤掉下面的数组b = ['ab','2']
我想从该列表中删除包含“ab”的字符串以及数组中的其他字符串,以便获得以下信息:
a = ['blah', 'tete', 'head']
例子:
a = ['abc123','abc','543234','blah','tete','head','loo2']
所以我想从上面的字符串数组中过滤掉下面的数组b = ['ab','2']
我想从该列表中删除包含“ab”的字符串以及数组中的其他字符串,以便获得以下信息:
a = ['blah', 'tete', 'head']
您可以使用列表推导:
[i for i in a if not any(x in i for x in b)]
这将返回:
['blah', 'tete', 'head']
>>> 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']
newA = []
for c in a:
for d in b:
if d not in c:
newA.append(c)
break
a = newA