Python 78
[Python 100] Python 100
(Python 2.0+)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__':
person = {"li":18,"wang":50,"zhang":20,"sun":22}
m = 'li'
for key in person.keys():
if person[m] < person[key]:
m = key
print '%s,%d' % (m,person[m])
wang,50
[Python 100] Python 100
ai
z@g***cc
#!/usr/bin/env python # -*- coding: UTF-8 -*- import operator __author__ = 'Lei Zhong' person = {"li":18,"wang":50,"zhang":20,"sun":22} print max(person.iteritems(), key=operator.itemgetter(1))[0] # key print max(person.values()) #ai
z@g***cc
cooqes
896***[email protected]
#!/usr/bin/env python #-*- coding: UTF-8 -*- person = {"li":18,"wang":50,"zhang":20,"sun":22} def find_max(dict): max_age = 0 for key, value in dict.items(): if value > max_age: max_age = value name = key print name print max_age find_max(person)cooqes
896***[email protected]