如何根据包含通配符的另一个列表筛选列表?

Bor*_*lis 7 python glob list

如何根据包含部分值和通配符的其他列表过滤列表?以下示例是我到目前为止的例子:

l1 = ['test1', 'test2', 'test3', 'test4', 'test5']
l2 = set(['*t1*', '*t4*'])

filtered = [x for x in l1 if x not in l2]
print filtered
Run Code Online (Sandbox Code Playgroud)

此示例导致:

['test1', 'test2', 'test3', 'test4', 'test5']
Run Code Online (Sandbox Code Playgroud)

但是,我希望根据l2以下内容限制结果:

['test2', 'test3', 'test5']
Run Code Online (Sandbox Code Playgroud)

Ash*_*ary 10

使用fnmatch模块和列表理解any():

>>> from fnmatch import fnmatch
>>> l1 = ['test1', 'test2', 'test3', 'test4', 'test5']
>>> l2 = set(['*t1*', '*t4*'])
>>> [x for x in l1 if not any(fnmatch(x, p) for p in l2)]
['test2', 'test3', 'test5']
Run Code Online (Sandbox Code Playgroud)