List of dictionaries with comprehension in python
问题 I have the following list of dictionaries: ld=[{'a':10,'b':20},{'p':10,'u':100}] I want to write a comprehension like this: [ (k,v) for k,v in [ d.items() for d in ld ] ] basically I want to iterate over dictionaries in the list and get the keys and values of each dict and do sth. Example: One example output of this would be for example another list of dictionaries without some keys: ld=[{'a':10,'b':20},{'p':10,'u':100}] new_ld=[{'a':10},{'p':10}] However, the above comprehension is not