擅长:python、mysql、java
<p>这只是一个解决方案,但我认为它简单明了。请注意,它会对字典进行适当的修改,因此,如果您希望将它们复制到<em>中,请告诉我,我会相应地进行修改。在</p>
<pre><code>keys_seen = []
for D in L: #loop through the list
for key in D.keys(): #loop through each dictionary's keys
if key not in keys_seen: #if we haven't seen this key before, then...
keys_seen.append(key) #add it to the list of keys seen
for D1 in L: #loop through the list again
for key in keys_seen: #loop through the list of keys that we've seen
if key not in D1: #if the dictionary is missing that key, then...
D1[key] = 0 #add it and set it to 0
</code></pre>