本文主要是介绍20180805:求出字典d = {'a':1,b:2,c:3,d:4,e:4}中的最大的字母,并打印出来,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法一:
# encoding=utf-8
d = {'a':1,"b":2,"c":3,"d":4,"e":4}
max_value= d['a']
result = []
for k,v in d.items():
print(k,v)
if v > max_value:
max_value =v
result = []
result.append(k)
elif v == max_value:
result.append(k)
print(result)
输出结果:
>>> print(result)
['d', 'e']
方法二:
d = {'a':1,"b":2,"c":3,"d":4,"e":4}
max_value= max(d.values())
result = []
for k,v in d.items():
if v == max_value:
result.append(k)
print(result)
输出结果:
>>> print(result)
['d', 'e']
这篇关于20180805:求出字典d = {'a':1,b:2,c:3,d:4,e:4}中的最大的字母,并打印出来的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!