【发布时间】:2022-12-02 17:17:25
【问题描述】:
Say I have a list of dict:
ld = [{\'a\':1,\'b\':2,\'c\':9},{\'a\':1,\'b\':2,\'c\':10}]
And a list to filter the keys out:
l = [\'a\',\'c\']
Want to remove key a and c from ld:
Try:
result = [d for d in ld for k in d if k in l]
Desired Result:
[{\'b\':2},{\'b\':2}]
-
why the downvote ? the question is clear.
标签: python