如何删除元组列表中的重叠元素?

我有一个元组列表

[('one','two','three'),('four','five','six'),('seven','eight','nine')]

和一个清单

['three','five','nine']

我想要做的是删除与

第二个清单,这样我就有了

[('one','two'),('four','six'),('seven','eight')]

有没有一种简单的方法可以做到这一点?


BIG阳
浏览 185回答 2
2回答

缥缈止盈

listoflists = [('one','two','three'),('four','five','six'),('seven','eight','nine')]toremove = ['three','five','nine']outcome = [tuple(item for item in list if item not in toremove) for list in listoflists]

幕布斯7119047

创建一个新的元组列表a=[('one','two','three'),('four','five','six'),('seven','eight','nine')]b=['three','five','nine'][set(i).difference(b) for i in a] # if you do not care about the order inside the tuple
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python