Hi, friends. I wanna ask if there is a function which is able to take a list as argument and then return its top-k maximums?

Raymond Hettinger python at rcn.com
Sat Apr 24 02:40:04 CEST 2010

On Apr 23, 1:24 am, Bryan <bryanjugglercryptograp... at yahoo.com> wrote:
> That is interesting. The above algorithm for nlargest is better, but
> to use it for nsmallest requires a largest-on-top heap, which the
> module does not bother to implement.

FWIW, the pure python versions differ because they are both
implemented in terms of the basic minheap functions, but the
underlying C code uses the same algorithm for both (using an
underlying maxheap when necessary):



More information about the Python-list mailing list