Yeah... but actually I need something more efficient, like heap. <div>Thank you for your help though.</div><div><br></div><div>Best regards,</div><div><br></div><div>Songjian<br><br><div class="gmail_quote">On Thu, Apr 22, 2010 at 10:04 PM, Tim Golden <span dir="ltr"><<a href="mailto:mail@timgolden.me.uk">mail@timgolden.me.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 22/04/2010 14:57, Jo Chan wrote:<br>
> Hi,friends.<br>
><br>
> I wanna ask if there is a function which is able to take a list as argument<br>
> and then return its top-k maximums?<br>
> I only know about max which is poorly a top-1 maximum function, now I want<br>
> more yet I am lazy enough that don't want to write one by myself.<br>
><br>
> So please tell me if there is one or not. I really need this soon.<br>
> Appreciate a lot.<br>
<br>
</div>Assuming top-k doesn't mean something obscurely statistical:<br>
<br>
l = [1,2, 3, 4, 5]<br>
k = 3<br>
print (sorted (l, reverse=True)[:k])<br>
<br>
TJG<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>------------------<br>Best Regards<br><br>陈松坚<br>信息科学与技术学院 中山大学 广州大学城 510006<br>Chen Songjian<br>School of Information Science & Technology<br>Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center, China, 510006<br>
Mobile: +86-137-6069-6137 <br>Email: <a href="mailto:csjcg2@gmail.com">csjcg2@gmail.com</a><br>
</div>