擅长:python、mysql、java
<p>这是问题的可选实现。在</p>
<p>首先,用True过滤所有的subkey1。在</p>
<p>其次,从过滤字典中找到subkey2中的最大值。在</p>
<pre><code>d = {'key1' : {'subkey1' : True, 'subkey2' : 4},
'key2' : {'subkey1' : True, 'subkey2' : 8},
'key3' : {'subkey1' : False, 'subkey2' : 1},
'key4' : {'subkey1' : False, 'subkey2' : 9} }
max_d = {v["subkey2"]:{k:v} for k,v in d.items() if v["subkey1"]} # create new dictionary that the key is the value from subkey2 and the value is the original key and value.
max_int = max(max_d.keys(), key=int) # get the max key
print (max_d[max_int]) # print the maximum
>>> {'key2': {'subkey1': True, 'subkey2': 8}}
</code></pre>