Python Practice Example 78
Question:Find the oldest person and output it. Please find out what's wrong with the program.
Program analysis:None.
Program source code:
Example (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])
The output of the above example is:
wang,50Other extensions
Python 100 Examples