Use max
:
>>> max(testDict, key=lambda x:len(testDict[x]))
32
If multiple keys contain the longest list:
I want to get multiple keys then.
>>> testDict = {76: [4], 32: [2, 4, 7, 3], 56: [2, 58, 59], 10: [1, 2, 3, 4]}
>>> mx = max(len(x) for x in testDict.itervalues())
>>> [k for k, v in testDict.iteritems() if len(v)==mx]
[32, 10]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…