我有dict
,如下所示:
a = {'abc':[0,1,2], 'def':[0,1,2,3,4], 'ghi':[0,1,2,3,4,5]}
想基于数组包含的key
长度来获取max
。就像这里
输出为'ghi'
。有人怎么做。我尝试过:
lambda x: max(len(x[1])), a.items()
但这并不能解决目的。谁能告诉我该怎么办?
答案 0 :(得分:5)
尝试:
max(a, key=lambda x: len(a[x]))
答案 1 :(得分:-1)
尝试一下:
a = {'abc':[0,1,2], 'def':[0,1,2,3,4], 'ghi':[0,1,2,3,4,5]}
print(list(a.keys())[list(a.values()).index(max(a.values()))])