def dict_top(d, k, n, reverse=False):
h = list()<EOL>for i in range(len(d)):<EOL><INDENT>heappush(h, (-d[i][k] if reverse else d[i][k], i))<EOL><DEDENT>r = list()<EOL>while len(r) < n and len(h) > <NUM_LIT:0>:<EOL><INDENT>_, i = heappop(h)<EOL>r.append(d[i].copy())<EOL><DEDENT>return r<EOL>
Return top n of a dictionary list sorted by key
:param d: dictionary list
:param k: key
:param n: top n
:param reverse: whether the value should be reversed
:return: top n of the sorted dictionary list