Steven D'Aprano wrote:
John Nagle wrote:
Is nlargest smart enough to decide when it's cheaper to track the
N largest entries on a linear pass through the list than to sort?
It *always* does a linear pass through the list (linear, that is in
the length of the entire list). It tracks the n
On 2010-04-22, D'Arcy J.M. Cain da...@druid.net wrote:
On Thu, 22 Apr 2010 15:04:01 +0100
Tim Golden m...@timgolden.me.uk wrote:
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:
You really
Really! Learn to use google better. I just used python sort list
Look at: http://wiki.python.org/moin/HowTo/Sorting
Read about list.sort. Try, at a command prompt (assuming you have a unix
shell), pydoc list
search for sort; read it. It mentions 'reverse'.
then slice the list to your desired
On Apr 22, 10:49 am, John Nagle na...@animats.com wrote:
Chris Rebert wrote:
2010/4/22 Jo Chan csj...@gmail.com:
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?
I only know about max which is poorly a top-1
On Apr 23, 1:24 am, Bryan bryanjugglercryptograp...@yahoo.com wrote:
That is interesting. The above algorithm for nlargest is better, but
to use it for nsmallest requires a largest-on-top heap, which the
module does not bother to implement.
FWIW, the pure python versions differ because they
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?
I only know about max which is poorly a top-1 maximum function, now I want
more yet I am lazy enough that don't want to write one by myself.
So please tell me if there is
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 argument
and then return its top-k maximums?
I only know about max which is poorly a top-1 maximum function, now I want
more yet I am lazy enough that don't want to write one
2010/4/22 Jo Chan csj...@gmail.com:
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?
I only know about max which is poorly a top-1 maximum function, now I want
more yet I am lazy enough that don't want to write one by
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]
Cool! Thanks a lot! That's exactly what I want.
Best regards,
Songjian
On Thu, Apr 22, 2010 at 10:04 PM, Chris Rebert creb...@ucsd.edu wrote:
2010/4/22 Jo Chan csj...@gmail.com:
Hi,friends.
I wanna ask if there is a function which is able to take a list as
argument
and then return its
Yeah... but actually I need something more efficient, like heap.
Thank you for your help though.
Best regards,
Songjian
On Thu, Apr 22, 2010 at 10:04 PM, Tim Golden m...@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
On Fri, 23 Apr 2010 00:07:18 +1000
Xavier Ho cont...@xavierho.com wrote:
print (sorted (l, reverse=True)[:k])
You don't really need to reverse sort there:
True but...
numbers = [1, 4, 5, 3, 7, 8]
sorted(numbers)[3:]
[5, 7, 8]
Now try returning the top two or four numbers.
--
D'Arcy
On Fri, Apr 23, 2010 at 12:23 AM, D'Arcy J.M. Cain da...@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
--
On Thu, 22 Apr 2010 15:04:01 +0100
Tim Golden m...@timgolden.me.uk wrote:
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:
You really shouldn't do people's homework for them. It doesn't do
Chris Rebert wrote:
2010/4/22 Jo Chan csj...@gmail.com:
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?
I only know about max which is poorly a top-1 maximum function, now I want
more yet I am lazy enough that don't
On Thu, 22 Apr 2010 15:23:29 +0100, D'Arcy J.M. Cain da...@druid.net
wrote:
On Fri, 23 Apr 2010 00:07:18 +1000
Xavier Ho cont...@xavierho.com wrote:
print (sorted (l, reverse=True)[:k])
You don't really need to reverse sort there:
True but...
numbers = [1, 4, 5, 3, 7, 8]
On Thu, 22 Apr 2010 10:49:29 -0700, John Nagle wrote:
Is nlargest smart enough to decide when it's cheaper to track the
N largest entries on a linear pass through the list than to sort?
Doesn't appear to do so. From Python 3.1:
def nlargest(n, iterable):
Find the n largest elements in
17 matches
Mail list logo