通过比较两个列表来删除特定单词

vic*_*ky 3 python list

我有两个清单。

x=['billed_qty','billed_amt','sale_value']

y=['george billed_qty', 'sam billed_amt', 'ricky sale_value', 'donald billed_qty']
Run Code Online (Sandbox Code Playgroud)

我需要消除列表y中出现在列表x中的单词,并希望结果列表为:

z=['george','sam','ricky','donald']
Run Code Online (Sandbox Code Playgroud)

我该如何实现?

谢谢

San*_*apa 7

使用regexlist comprehension

comp = re.compile('|'.join(x))
z = [re.sub(comp, '', i).strip() for i in y]

print(z)
['george','sam','ricky','donald']
Run Code Online (Sandbox Code Playgroud)