On Apr 23, 1:24 am, Bryan 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 are both
implemented in terms of th
On Apr 22, 10:49 am, John Nagle wrote:
> Chris Rebert wrote:
> > 2010/4/22 Jo Chan :
> >> 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?
> >>
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 desi
On 2010-04-22, D'Arcy J.M. Cain wrote:
> On Thu, 22 Apr 2010 15:04:01 +0100
> Tim Golden 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 h
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
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 elemen
On Thu, 22 Apr 2010 15:23:29 +0100, D'Arcy J.M. Cain
wrote:
On Fri, 23 Apr 2010 00:07:18 +1000
Xavier Ho 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 r
Chris Rebert wrote:
2010/4/22 Jo Chan :
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 writ
On Thu, 22 Apr 2010 15:04:01 +0100
Tim Golden 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
them any favours.
On Fri, Apr 23, 2010 at 12:23 AM, D'Arcy J.M. Cain 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
--
http://mail
On Fri, 23 Apr 2010 00:07:18 +1000
Xavier Ho 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 J.M. Cai
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 wrote:
> On 22/04/2010 14:57, Jo Chan wrote:
> > Hi,friends.
> >
> > I wanna ask if there is a function
Cool! Thanks a lot! That's exactly what I want.
Best regards,
Songjian
On Thu, Apr 22, 2010 at 10:04 PM, Chris Rebert wrote:
> 2010/4/22 Jo Chan :
> > Hi,friends.
> > I wanna ask if there is a function which is able to take a list as
> argument
> > and then ret
On Fri, Apr 23, 2010 at 12:04 AM, Tim Golden 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,
2010/4/22 Jo Chan :
> 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
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
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 the
hi friends... google group invites you a wondering world of
businesss . do u want to earn millions of dollers per
month through online jobs joined with me and find the way to earn
dollers. visit us www.jobsforyouguys.blogspot.com
--
http://mail.python.org/mailman
to get preapred for the business see bird-flumanual.com
log on to
http://www.geocities.com/humnoses/
--
http://mail.python.org/mailman/listinfo/python-list
19 matches
Mail list logo