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?

Xavier Ho contact at xavierho.com
Thu Apr 22 16:30:24 CEST 2010


On Fri, Apr 23, 2010 at 12:23 AM, D'Arcy J.M. Cain <darcy at druid.net> wrote:

> Now try returning the top two or four numbers.
>

 >>> numbers = [1, 4, 5, 3, 7, 8]
>>> sorted(numbers)[-2:]
[7, 8]
>>> sorted(numbers)[-4:]
[4, 5, 7, 8]

I see what you mean. This is not as intuitive, is it?

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100423/2d19bf71/attachment.html>


More information about the Python-list mailing list