On Fri, Apr 23, 2010 at 12:04 AM, Tim Golden <m...@timgolden.me.uk> wrote:

> Assuming top-k doesn't mean something obscurely statistical:
>
> l = [1,2, 3, 4, 5]
> k = 3
> print (sorted (l, reverse=True)[:k])
>

You don't really need to reverse sort there:

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

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to