假设我们有一个字典,
dict = {'blue': ['sky','sea'], 'orange': ['carrots','sunset','oranges'], 'green': ['grass']}
输出应该是
['carrots','sunset','oranges']
因为它获得了最多的值。
这是我目前所拥有的:
for k,v in dict.items():
print(max(k,len(v)))
请您参考如下方法:
为什么不只是:
>>> d = {'blue': ['sky','sea'], 'orange': ['carrots','sunset','oranges'], 'green': ['grass']}
>>> print max(d.values(), key=len)
['carrots', 'sunset', 'oranges']
字典最好不要也命名为dict。这将覆盖内置类型。
