How do I remove from list a all dictionaries which link value is included in list b?
a = [{'link':'http://example.com/1/', 'id': 1}, {'link':'http://example.com/2/', 'id': 2}]
b = ['http://example.com/2/', 'http://example.com/3/']
a should be:
a = [{'link':'http://example.com/1/', 'id': 1}]
a = [x for x in a if x['link'] not in b]
Demo:
>>> a = [{'link':'http://example.com/1/', 'id': 1}, {'link':'http://example.com/2/', 'id': 2}]
>>> b = ['http://example.com/2/', 'http://example.com/3/']
>>> a = [x for x in a if x['link'] not in b]
>>> a
[{'link': 'http://example.com/1/', 'id': 1}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With