我有一个元组列表
[('one','two','three'),('four','five','six'),('seven','eight','nine')]
和列表
['three','five','nine']
我要做的是删除与
重叠的元组的任何元素第二个列表,这样我就可以了
[('one','two'),('four','six'),('seven','eight')]
有一种简单的方法吗?
答案 0 :(得分:1)
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]
答案 1 :(得分:0)
创建一个新的元组列表
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