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:
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 for x in total if x[1] not in processed]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.