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?
D'Arcy J.M. Cain
darcy at druid.net
Thu Apr 22 16:23:29 CEST 2010
On Fri, 23 Apr 2010 00:07:18 +1000
Xavier Ho <contact at xavierho.com> wrote:
> > 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]
Now try returning the top two or four numbers.
D'Arcy J.M. Cain <darcy at druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
More information about the Python-list