0

例子:

a = ['abc123','abc','543234','blah','tete','head','loo2']

所以我想从上面的字符串数组中过滤掉下面的数组b = ['ab','2']

我想从该列表中删除包含“ab”的字符串以及数组中的其他字符串,以便获得以下信息:

a = ['blah', 'tete', 'head']
4

3 回答 3

5

您可以使用列表推导:

[i for i in a if not any(x in i for x in b)]

这将返回:

['blah', 'tete', 'head']
于 2013-07-31T13:42:05.523 回答
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']
于 2013-07-31T13:49:31.210 回答
1
newA = []
for c in a:
    for d in b:
        if d not in c:
            newA.append(c)
            break
a = newA
于 2013-07-31T13:44:36.710 回答