I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.
I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.
Is there any existing easy, pythonic way of doing this?
What I want is following function instead of a pure sort. Actually I don't want waste time to sort the elements I don't care.
For example, this is the function I'd like to have:
getSortedElements(100, lambda x,y:cmp(x,y))
Note this requirement is only for performance perspective.