-
利用
min(dict, key=dict.get)
>>> d = {1:1, 2:0, 3:2} {1: 1, 2: 0, 3: 2} >>> min(d, key=d.get) 2
-
利用lambda函数
>>> min(d.items(), key=lambda x: x[1]) (2, 0) >>> min(d, key=lambda x: d[x]) 2
原文地址:http://www.cnblogs.com/harvey888/p/6006202.html
利用min(dict, key=dict.get)
>>> d = {1:1, 2:0, 3:2}
{1: 1, 2: 0, 3: 2}
>>> min(d, key=d.get)
2
利用lambda函数
>>> min(d.items(), key=lambda x: x[1])
(2, 0)
>>> min(d, key=lambda x: d[x]) 2
原文地址:http://www.cnblogs.com/harvey888/p/6006202.html