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?
csjcg2 at gmail.com
Thu Apr 22 16:10:41 CEST 2010
Yeah... but actually I need something more efficient, like heap.
Thank you for your help though.
On Thu, Apr 22, 2010 at 10:04 PM, Tim Golden <mail at timgolden.me.uk> wrote:
> On 22/04/2010 14:57, Jo Chan wrote:
> > Hi,friends.
> > I wanna ask if there is a function which is able to take a list as
> > and then return its top-k maximums?
> > I only know about max which is poorly a top-1 maximum function, now I
> > more yet I am lazy enough that don't want to write one by myself.
> > So please tell me if there is one or not. I really need this soon.
> > Appreciate a lot.
> Assuming top-k doesn't mean something obscurely statistical:
> l = [1,2, 3, 4, 5]
> k = 3
> print (sorted (l, reverse=True)[:k])
信息科学与技术学院 中山大学 广州大学城 510006
School of Information Science & Technology
Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center,
Email: csjcg2 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list