What´s the most efficient, elegant and pythonic way of solving this problem?
Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( Yo
You can use the heapq module.
heapq
>>> from heapq import heapify, nlargest >>> l = [9,1,6,4,2,8,3,7,5] >>> heapify(l) >>> nlargest(3, l) [9, 8, 7] >>>