简体   繁体   English

从 dic 列表中删除子列表

[英]Remove sublist from list of dic

I have these two lists and I would like to remove those elements already processes from total list.我有这两个列表,我想从总列表中删除那些已经处理的元素。

processed = ['a','b','c']

total = [(1, 'a', 'alaksdl'),
         (2, 'x', 'asda'),
         (3, 'b', 'asda'),
         (4, 'c', 'wef'),
         (5, 'e', 'asaaa'),         
         (5, 'j', 'asd')                     
]

So, my final desired output would be:所以,我最终想要的 output 将是:

total = [(2, 'x', 'asda'),(5, 'e', 'asaaa'),(5, 'j', 'asd')]

Simply use list comprehension and make sure x[1] will not in processed list.只需使用列表推导并确保x[1]不在processed列表中。

[x for x in total if x[1] not in processed]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM