1import heapq
2from operator import itemgetter
3
4n = 3
5
6items = {'a': 7, 'b': 12, 'c': 9, 'd': 0, 'e': 24, 'f': 10, 'g': 24}
7
8topitems = heapq.nlargest(n, items.items(), key=itemgetter(1)) # Use .iteritems() on Py2
9topitemsasdict = dict(topitems)