给定以下字典,我想找出哪个键的值最多。如果我有一个更长的字典并且想知道哪个键以编程方式具有最多的值(没有目视检查),我将如何去做呢?我能想到的唯一方法如下:
dic = {'attacks': ['kick','puch','slap','elbow'], \
'defense': ['block','parry','dodge']}
dic = {'攻击':['踢','puch','slap','肘部'],'防御':['block','parry','dodge']}
key_values_list = []
for key in dic:
key_name = ''
num = 0
for item in dic[key]:
num +=1
key_values_list.append((key,num))
for k,v in key_values_list:
print k,v