In [12]: import heapq
In [13]: from operator import itemgetter
In [14]: scores = [ {'student_name': 'zhangsan', 'student_score': 65}, {'student_name': 'lisi', 'student_score': 95}, {'student_name':'wangwu', 'student_score': 80}, {'student_name': 'maliu', 'student_sco
...: re': 75}, {'student_name': 'zhuqi', 'student_score': 88} ]
In [15]: heapq.nlargest(3, scores, key=itemgetter('student_score'))
Out[15]:
[{'student_name': 'lisi', 'student_score': 95},
{'student_name': 'zhuqi', 'student_score': 88},
{'student_name': 'wangwu', 'student_score': 80}]