擅长:python、mysql、java
<p>我认为你的方法是相当python的,只是我要把<code>update</code>行改得更清楚一点:</p>
<pre><code># A little terse
dct.update({key: max(dct.get(key,0), len(str(l.get(key,0))))})
# A little simpler
dct[key] = max(dct.get(key, 0), len(str(l[key])))
</code></pre>
<p>下面是一个同时修改变量名的解决方案:</p>
<pre><code>dict_list =[{'a':'asdasd', 'b': 123},{'a': 'asdasdasdas'}, {'a':123,'b':'asdasd'}]
max_lengths = {}
for dictionary in dict_list:
for k, v in dictionary.items():
max_lengths[k] = max(max_lengths.get(k, 0), len(str(v)))
print(max_lengths)
</code></pre>